-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbootstrap-external-options.min.js
1 lines (1 loc) · 5.41 KB
/
bootstrap-external-options.min.js
1
angular.module("schemaForm").run(["$templateCache",function(e){e.put("directives/decorators/bootstrap/external-options/external-options.html",'<div class="form-group" ng-class="{\'has-error\': hasError(), \'has-success\': hasSuccess(), \'has-feedback\': form.feedback !== false, \'float\': form.float === true }"><label class="control-label" ng-show="showTitle()">{{form.title}}</label><select ng-model="form.selectedOption" ng-model-options="form.ngModelOptions" ng-disabled="form.readonly" sf-changed="form" ng-change="changed()" class="form-control" schema-validate="form" external-options="" links="form.schema.links" model="model" form="form" test="evalExpr(this)" ng-options="item.value as item.name for item in form.options" destroy-hidden-data=""><option ng-show="form.selectedOption" value=""></option></select><div class="help-block" ng-show="(hasError() && errorMessage(schemaError()))" ng-bind-html="(hasError() && errorMessage(schemaError()))"></div></div>')}]),angular.module("schemaForm").directive("externalOptions",function(){return{restrict:"A",require:["ngModel","?^sfSchema"],scope:{test:"=",form:"=",model:"="},controller:["$scope","$http","$interpolate","$filter","sfSelect",function(e,o,t,r,n){var i,a=e;a.form.options=[],a.currentSource="",a.externalOptions={};var l=function(e,o,t){var r=[];if(o["enum"]&&o["enum"].length){for(i=0;i<o["enum"].length;i++)o["enum"][i]&&o["enum"][i].length&&r.push({name:o["enum"][i],value:o["enum"][i]});a.form.options=r}else o.titleMap&&(a.form.options=o.titleMap);a.externalOptions[e]!==o&&(a.externalOptions[e]=o),a.$watch("form.selectedOption",function(){n(a.form.key,a.model,a.form.selectedOption)});for(var i=0;i<a.form.options.length;i++)if("undefined"!=typeof a.form.options[i].value&&t===a.form.options[i].value)return void(a.form.selectedOption=a.form.options[i].value);n(a.form.key,a.model,"null")},s=function(e){if(a.currentSource!==e||"object"!=typeof a.externalOptions[e]){a.currentSource=e;var t=n(a.form.key,a.model);return t=t?t:void 0,e=r("_externalOptionUri")(e),"object"==typeof a.externalOptions[e]?void l(e,a.externalOptions[e],t):void o.get(e,{responseType:"json"}).success(function(o){l(e,o,t)}).error(function(){a.form.options=[],a.form.selectedOption="",n(a.form.key,a.model,a.form.selectedOption)})}};if(a.form.optionData)a.$parent.evalExpr("this").$watchCollection(a.form.optionData,function(e){var o={};angular.isArray(e)&&e.length&&(o=angular.isString(e[0])?{"enum":e}:{titleMap:e}),l("data:"+a.form.optionData,o,a.form.selectedOption)});else if(a.form.parameters&&a.form.parameters.length)for(var i=0;i<a.form.parameters.length;i++)angular.isDefined(a.form.parameters[i])&&a.$watch(a.form.parameters[i][1],function(e){var o,n,e=r("_externalOptionUriField")(e);e?(o=t(a.form.optionSource,!1,null,!0),n=o(a),s(n,a.form.key)):a.form.options=[]});else s(a.form.optionSource)}]}}).filter("_externalOptionUriField",["$injector","$filter",function(e,o){var t=function(t){return e.has("externalOptionUriFieldFilter")&&(t=o("externalOptionUriField")(t)),t};return t}]).filter("_externalOptionUri",["$injector","$filter",function(e,o){var t=function(t){return e.has("externalOptionUriFilter")&&(t=o("externalOptionUri")(t)),t};return t}]),function(e){"use strict";e.module("schemaForm").directive("destroyHiddenData",["sfSelect",function(e){return{link:function(o){var t=!1;o.$on("$destroy",function(){"object"==typeof o.form.preserveOnDestroy&&o.form.preserveOnDestroy.condition?t=o.evalExpr(o.form.preserveOnDestroy.condition):o.form.preserveOnDestroy&&(t=!0),t||(o.form.selectedOption="",e(o.form.key,o.model,o.form.selectedOption))})}}}])}(window.angular),function(e){"use strict";e.module("schemaForm").directive("oyInline",["schemaForm","sfValidator","sfPath","sfSelect",function(o,t,r){return{restrict:"A",require:"ngModel",scope:{oyInline:"=",ngModel:"=",ngModelOptions:"=",model:"=",sfChanged:"=",schemaValidate:"="},link:function(o,t,n,i){var a=r.stringify(o.schemaValidate.key),l={},s=o.schemaValidate.title||o.schemaValidate.key.join(".")||"";e.copy(o.schemaValidate.schema,l),l.properties&&l.anyOf&&(o.schemaValidate.schema.allowInvalid=!0,delete l.properties),i.$name=s,i.$options.allowInvalid=!0,o.$watchCollection("model"+a,function(){i.$validate?(i.$validate(),i.$invalid&&(i.$dirty=!0,i.$pristine=!1)):i.$setViewValue(i.$viewValue)}),i.$validators={anyOf:function(){return tv4.validate(o.ngModel,l),tv4.valid}},o.$on("schemaFormValidate",function(){i.$validate?(i.$validate(),i.$invalid&&(i.$dirty=!0,i.$pristine=!1)):i.$setViewValue(i.$viewValue)})}}}])}(window.angular),angular.module("schemaForm").config(["schemaFormProvider","schemaFormDecoratorsProvider","sfPathProvider",function(e,o,t){var r,n;n=function(o,n,i){var n=n||{},a="string"===n.type?"string":n.type;if("Array"==typeof a&&(a=!!n.type.indexOf("string")),a&&n.links&&"object"==typeof n.links)for(r=0;r<n.links.length;r++)if("options"===n.links[r].rel){var l=/({)([^}]*)(})/gm,s=/{{([^}]*)}}/gm,c=e.stdFormObj(o,n,i);c.key=i.path,c.type="select-external",c.optionSource=n.links[r].href.replace(l,"$1$1 model.$2 | _externalOptionUri $3$3"),c.options=[],c.schema=n,c.parameters=[];for(var m=c.optionSource.match(s);null!==(m=s.exec(c.optionSource));)c.parameters.push(m);return i.lookup[t.stringify(i.path)]=c,c}},e.defaults.string.unshift(n),o.addMapping("bootstrapDecorator","select-external","directives/decorators/bootstrap/external-options/external-options.html"),o.createDirective("select-external","directives/decorators/bootstrap/external-options/external-options.html")}]);