gumga-custom-fields-ng
Version:
Gumga Custom Fields (Angular 1.x)
1 lines • 3.45 kB
JavaScript
!function(e){function t(l){if(n[l])return n[l].exports;var i=n[l]={i:l,l:!1,exports:{}};return e[l].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,l){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:l})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(module,exports,__webpack_require__){"use strict";!function(){function CustomFields(){return{restrict:"E",scope:{fields:"=",useLabels:"=?"},bindToController:!0,controller:["$scope","$element","$attrs","$http","$compile","$filter",function($scope,$element,$attrs,$http,$compile,$filter){var ctrl=this;ctrl.open=function(){ctrl.isDatePickerOpen=!ctrl.isDatePickerOpen},setTimeout(function(){if(!ctrl.fields)throw"O componente gumgaCustomFields requer o escopo populado com os fields para geração do template.";angular.forEach(ctrl.fields.gumgaCustomFields,function(v){angular.isString(v.field.options)&&"SELECTION"==v.field.type&&"["==v.field.options.charAt(0)?v.field.selection=JSON.parse(v.field.options):angular.isString(v.field.options)&&"SELECTION"==v.field.type&&"["!=v.field.options.charAt(0)&&$http.get(v.field.options).then(function(e){v.field.selection=e.data[v.field.optionsCollection],v.field.selection.forEach(function(e){return e[v.field.optionValueField]=e[v.field.optionValueField].toString()})},function(e){console.error(e)}),"DATE"==v.field.type&&(v.dateValue?v.dateValue=new Date(v.dateValue):v.field.defaultValueScript&&(v.dateValue=eval(v.field.defaultValueScript)),$scope.$apply())})},500);var template='\n <div class="row">\n <div class="col-md-{{f.field.colSize || 12}}" ng-if="f.field.active" ng-repeat="f in ctrl.fields.gumgaCustomFields">\n <label ng-bind="f.field.name" ng-if="!ctrl.useLabels" gumga-translate-tag="f.field.translateKey"></label>\n <label ng-if="ctrl.useLabels">{{f.field.translateKey}}</label>\n <div ng-switch="f.field.type" class="form-group">\n <div ng-switch-when="TEXT">\n <input type="text" ng-model="f.textValue" class="form-control" />\n </div>\n <div ng-switch-when="NUMBER">\n <input type="number" ng-model="f.numberValue" class="form-control" />\n </div>\n <div ng-switch-when="DATE">\n <gumga-date ng-model="f.dateValue"></gumga-date>\n </div>\n <div ng-switch-when="SELECTION">\n <select ng-options="opt[f.field.optionValueField] as opt[f.field.optionLabelField] for opt in f.field.selection" ng-model="f.textValue" class="form-control"></select>\n </div>\n <div ng-switch-when="LOGIC">\n <button type="button" class="btn" ng-class="{\'btn-success\': f.logicValue, \'btn-default\': !f.logicValue}" ng-model="f.logicValue" uib-btn-checkbox btn-checkbox-true="true" btn-checkbox-false="false">\n {{(f.logicValue) ? "On" : "Off" }}\n </button>\n </div>\n </div>\n </div>\n </div>\n ';$element.append($compile(template)($scope))}],controllerAs:"ctrl"}}CustomFields.$inject=[],angular.module("gumga.customfields",["gumga.date"]).directive("gumgaCustomFields",CustomFields)}()}]);