/********************************************* * Copyright (c) 2013 AnsibleWorks, Inc. * * GeneratorHelpers * * Functions shared between FormGenerator and ListGenerator * */ angular.module('GeneratorHelpers', ['GeneratorHelpers']) .factory('Attr', function() { return function(obj, key) { var result; var value = (typeof obj[key] === "string") ? obj[key].replace(/\'/g, '"') : obj[key]; switch(key) { case 'ngClick': result = "ng-click=\"" + value + "\" "; break; case 'ngOptions': result = "ng-options=\"" + value + "\" "; break; case 'ngClass': result = "ng-class=\"" + value + "\" "; break; case 'ngChange': result = "ng-change=\"" + value + "\" "; break; case 'ngDisabled': result = "ng-disabled=\"" + value + "\" "; break; case 'ngShow': result = "ng-show=\"" + value + "\" "; break; case 'ngHide': result = "ng-hide=\"" + value + "\" "; break; case 'ngBind': result = "ng-bind=\"" + value + "\" "; break; case 'trueValue': result = "ng-true-value=\"" + value + "\" "; break; case 'falseValue': result = "ng-false-value=\"" + value + "\" "; break; case 'awToolTip': result = "aw-tool-tip=\"" + value + "\" "; break; case 'awPopOver': result = "aw-pop-over='" + value + "' "; break; case 'dataTitle': result = "data-title=\"" + value + "\" "; break; case 'dataPlacement': result = "data-placement=\"" + value + "\" "; break; case 'dataContainer': result = "data-container=\"" + value + "\" "; break; default: result = key + "=\"" + value + "\" "; } return result; } }) .factory('Icon', function() { return function(icon) { return " "; } }) .factory('Column', ['Attr', 'Icon', function(Attr, Icon) { return function(params) { var list = params['list']; var fld = params['fld']; var options = params['options']; var base = params['base']; var field = list['fields'][fld]; var html = ''; html += "" : ""; // Add collapse/expand icon --used on job_events page if (list['hasChildren'] && field.hasChildren) { html += " " + " "; } // Start the Link if ((field.key || field.link || field.linkTo || field.ngClick ) && options['mode'] != 'lookup' && options['mode'] != 'select') { if (field.linkTo) { html += ""; } else if (field.ngClick) { html += ""; } else if (field.link == undefined || field.link) { html += ""; } } // Add icon: if (field.ngShowIcon) { html += " "; } else { if (field.icon) { html += Icon(field.icon) + " "; } } // Add data binds if (field.showValue == undefined || field.showValue == true) { if (field.ngBind) { html += "{{ " + field.ngBind + " }}"; } else { html += "{{" + list.iterator + "." + fld + "}}"; } } // Add additional text: if (field.text) { html += field.text; } if (list['hasChildren'] && field.hasChildren) { html += ""; } // close the link if ((field.key || field.link || field.linkTo || field.ngClick ) && options.mode != 'lookup' && options.mode != 'select') { html += ""; } // close ngShow html += (field.ngShow) ? "" : ""; // Specific to Job Events page -showing event detail/results html += (field.appendHTML) ? "
\n" : ""; return html += "\n"; } }]) .factory('SearchWidget', function() { return function(params) { // // Generate search widget // var iterator = params.iterator; var form = params.template; var useMini = params.mini; var label = (params.label) ? params.label : null; var html= ''; html += "
\n"; html += (label) ? "" : ""; html += "
\n"; html += "
\n"; html += "\n"; html += "
    \n"; for ( var fld in form.fields) { if (form.fields[fld].searchable == undefined || form.fields[fld].searchable == true) { html += "
  • " + form.fields[fld].label + "
  • \n"; } } html += "
\n"; html += "
\n"; html += "\n"; html += "\n"; html += "
\n"; html += "\n"; html += "\n"; html += "
\n"; html += "
\n"; html += "
\n"; html += "
\n"; return html; } }) .factory('PaginateWidget', function() { return function(params) { var set = params.set; var iterator = params.iterator; var useMini = params.mini; var mode = (params.mode) ? params.mode : null; var html = ''; if (mode == 'lookup') { html += "
\n"; html += "
\n"; html += "\n"; html += "\n"; if (mode != 'lookup') { html += "\n"; html += "\n"; } html += "
0\" "; html += ">Page: {{ " + iterator + "Page + 1 }} of {{ " + iterator + "PageCount }}
\n"; html += "
\n"; html += "
\n"; return html; } });