<commit_before>/*! forms-angular 2013-07-08 */
"use strict";var formsAngular=angular.module("formsAngular",["ui.select2","ui.date","fng.ui.bootstrap"]);formsAngular.value("ui.config",{date:{dateFormat:"dd/mm/yy"}}),formsAngular.controller("BaseCtrl",["$scope","$routeParams","$location","$http","$filter","$data","$locationParse",function(a,b,c,d,e,f,g){function h(a,b,c){var d="#"+(c?"cg_":"")+b;a?$(d).removeClass(o):$(d).addClass(o)}function i(a){var b=a.split("."),c=[b[0]];return b.length>1&&c.push(b.slice(1).join(".")),c}function j(a,b,c){var d=i(a);if(d.length>1)k(d[1],b[d[0]],c);else if(b[d[0]]){var e=b[d[0]];b[d[0]]=c("Object"==typeof e?e.x:e)}}function k(a,b,c){if(void 0!==b)if($.isArray(b))for(var d=0;d<b.length;d++)j(a,b[d],c);else j(a,b,c)}function l(a,b,c,d){if(a.array){for(var e=[],f=0;f<b.length;f++)e.push({x:C(b[f],d,c,a.name)});return e}return C(b,d,c,a.name)}function m(a,b,c,d){if(a.array){for(var e=[],f=0;f<b.length;f++)e.push(D(b[f].x,c,d,a.name));return e}return D(b,c,d,a.name)}var n={},o="fng-invalid-required",p=f;a.record=p.record,a.disableFunctions=p.disableFunctions,a.formSchema=[],a.panes=[],a.listSchema=[],a.recordList=[],a.dataDependencies={},a.select2List=[],angular.extend(a,g(c.$$path)),a.formPlusSlash=a.formName?a.formName+"/":"",a.modelNameDisplay=e("titleCase")(a.modelName);var q=function(a,b){return a.id.replace(/\./g,"_")+b},r=function(b,e,f){var g;if(e.caster&&(b.array=!0,e=e.caster,$.extend(f,e.options)),"String"==e.instance)f.enum?(b.type="select",f.required&&(a.$watch("record."+b.name,function(a){h(a,b.id,b.select2)},!0),setTimeout(function(){h(a.record[b.name],b.id,b.select2)},0)),b.select2?(a["select2"+b.name]={allowClear:!f.required,initSelection:function(a,b){var c=a.val(),d={id:c,text:c};b(d)},query:function(a){for(var b={results:[]},c=a.term.toUpperCase(),d=0;d<f.enum.length;d++)-1!==f.enum[d].toUpperCase().indexOf(c)&&b.results.push({id:d,text:f.enum[d]});a.callback(b)}},_.extend(a["select2"+b.name],b.select2),b.select2.s2query="select2"+b.name,a.select2List.push(b.name)):(b.options=q(b,"Options"),a[b.options]=f.enum)):b.type||(b.type="text");else if("ObjectID"==e.instance)b.ref=f.ref,b.link&&b.link.linkOnly?(b.type="link",b.linkText=b.link.text,delete b.link):(b.type="select",b.select2?(a.select2List.push(b.name),b.select2.fngAjax?(g="ajax"+b.name.replace(/\./g,""),a[g]={allowClear:!f.required,minimumInputLength:2,initSelection:function(a,e){d.get("api/"+f.ref+"/"+a.val()+"/list").success(function(d){d.success===!1&&c.path("/404");var f={id:a.val(),text:d.list};n[b.name]=f,e(f)}).error(function(){c.path("/404")})},ajax:{url:"/api/search/"+f.ref,data:function(a,b){return{q:a,page_limit:10,page:b}},results:function(a){return{results:a.results,more:a.moreCount>0}}}},_.extend(a[g],b.select2),b.select2.fngAjax=g):(1==b.select2&&(b.select2={}),a["select2"+b.name]={allowClear:!f.required,initSelection:function(c,d){var e,f=c.val();e=a[b.options].length>0?D(f,a[b.options],a[b.ids],b.name):f;var g={id:e,text:f};d(g)},query:function(c){for(var d={results:[]},e=c.term.toUpperCase(),f=0;f<a[b.options].length;f++)-1!==a[b.options][f].toUpperCase().indexOf(e)&&d.results.push({id:a[b.ids][f],text:a[b.options][f]});c.callback(d)}},_.extend(a["select2"+b.name],b.select2),b.select2.s2query="select2"+b.name,a.select2List.push(b.name),b.options=q(b,"Options"),b.ids=q(b,"_ids"),E(f.ref,b))):(b.options=q(b,"Options"),b.ids=q(b,"_ids"),E(f.ref,b)));else if("Date"==e.instance)b.type="text",b.add="ui-date ui-date-format ";else if("boolean"==e.instance)b.type="checkbox";else{if("Number"!=e.instance)throw new Error("Field "+b.name+" is of unsupported type "+e.instance);b.type="number"}return f.required&&(b.required=!0),f.readonly&&(b.readonly=!0),b},s=function(a,b,c){return b.name=c+a,b.id=b.id||"f_"+c+a,b.label=null==(b.hasOwnProperty("label")&&b.label)?"":b.label||e("titleCase")(a),b},t=function(a,b,c){var d=b||{hidden:!0};d.hidden||("object"==typeof d?(d.name=c,a.push(d)):a.push({name:c}))},u=function(a,b,c,d){if(c){for(var e=0,f=c.length;f>e;e++)if("text"==c[e].type){b.push({name:c[e].name});break}0===b.length&&0!==c.length&&b.push({name:c[0].name})}if(0===b.length){for(var g in d)if("_id"!==g&&d.hasOwnProperty(g)){b.push({name:g});break}if(0===b.length)throw new Error("Unable to generate a title for "+a)}},v=function(b,c){function d(b){var d=b;return"string"==typeof b&&"$"===b.slice(0,1)&&(d=a.getListData(c,b.slice(1))),d}var e,f=d(b.lhs),g=d(b.rhs);switch(b.comp){case"eq":e=f===g;break;case"ne":e=f!==g;break;default:throw new Error("Unsupported comparator "+b.comp)}return e},w=function(b,c){function d(b){if("string"==typeof b&&"$"===b.slice(0,1)){var d=b.slice(1),f=a.dataDependencies[d]||[];f.push(c),a.dataDependencies[d]=f,e+=1}}var e=0,f=!0;return b&&(d(b.lhs),d(b.rhs),0!==e||v(b)||(f=!1)),f};a.getListData=function(b,c){for(var d=c.split("."),e=0;e<d.length;e++)void 0!==b&&(b=b[d[e]]);return b&&-1!==a.select2List.indexOf(d[e-1])&&(b=b.text),void 0===b&&(b=""),b},a.updateDataDependentDisplay=function(b,c,d){for(var e in a.dataDependencies)if(a.dataDependencies.hasOwnProperty(e)&&(d||b[e]!=c[e]))for(var f=a.dataDependencies[e],g=0;g<f.length;g+=1)for(var h=f[g],i=0;i<a.formSchema.length;i+=1)if(a.formSchema[i].id===h){var j=$("#cg_"+h);v(a.formSchema[i].showIf,b)?j.show():j.hide()}};var x=function(b,c,d,e,f,g){function h(b,c){var d=angular.copy(b),e=_.find(a.panes,function(a){return a.title===d});if(!e){var f=!1;if(0===a.panes.length)if(a.formSchema.length>0){a.panes.push({title:"Main",content:[],active:!0}),e=a.panes[0];for(var g=0;g<a.formSchema.length;g++)e.content.push(a.formSchema[g])}else f=!0;e=a.panes[a.panes.push({title:d,content:[],active:f})-1]}e.content.push(c)}for(var i in c)if("_id"!==i&&c.hasOwnProperty(i)){var j=c[i],k=j.options||{},l=k.form||{};if(!l.hidden)if(j.schema){if(g&&d){var m=[];x("Nested "+i,j.schema,m,null,i+".",!0);var n=s(i,l,f);n.schema=m,l.pane&&h(l.pane,n),d.push(n)}}else{if(d){var o=s(i,l,f);if(w(o.showIf,o.id)){var p=r(o,j,k);p.pane&&h(p.pane,p),d.push(p)}}e&&t(e,k.list,i)}}e&&0===e.length&&u(b,e,d,c)};d.get("api/schema/"+a.modelName+(a.formName?"/"+a.formName:""),{cache:!0}).success(function(e){if(x("Main "+a.modelName,e,a.formSchema,a.listSchema,"",!0),a.id||a.newRecord)a.$watch("record",function(b,c){a.updateDataDependentDisplay(b,c,!1)},!0),a.id?d.get("api/"+a.modelName+"/"+a.id).success(function(b){b.success===!1&&c.path("/404"),n=A(a.formSchema,b,0),a.cancel()}).error(function(){c.path("/404")}):(n={},a.cancel());else{var f="?",g="";b.f&&(g+=f+"f="+b.f,f="&"),b.a&&(g+=f+"a="+b.a),d.get("api/"+a.modelName+g).success(function(b){a.recordList=b}).error(function(){c.path("/404")})}}).error(function(){c.path("/404")}),a.cancel=function(){var b;for(b in a.record)a.record.hasOwnProperty(b)&&delete a.record[b];for(b in n)n.hasOwnProperty(b)&&(a.record[b]=n[b]);a.dismissError()};var y=function(a,b){if(-1!==[200,400].indexOf(b)){var c="";for(var d in a.errors)if(a.errors.hasOwnProperty(d)){switch(c+="<li><b>"+e("titleCase")(d)+": </b> ",a.errors[d].type){case"enum":c+="You need to select from the list of values";break;default:c+=a.errors[d].message}c+="</li>"}c=c.length>0?a.message+"<br /><ul>"+c+"</ul>":a.message||"Error!  Sorry - No further details available.",z(c)}else z(b+" "+JSON.stringify(a))},z=function(b,c){a.alertTitle=c?c:"Error!",a.errorMessage=b};a.dismissError=function(){delete a.errorMessage},a.save=function(b){b=b||{};var e=B(a.formSchema,angular.copy(a.record),0);a.record._id?d.post("api/"+a.modelName+"/"+a.id,e).success(function(c){c.success!==!1?b.redirect?window.location=b.redirect:(n=c,a.cancel()):z(c)}).error(y):d.post("api/"+a.modelName,e).success(function(d){d.success!==!1?b.redirect?window.location=b.redirect:c.path("/"+a.modelName+"/"+d._id+"/edit"):z(d)}).error(y)},a.new=function(){c.path("/"+a.modelName+"/new")},a.delete=function(){a.record._id&&d.delete("api/"+a.modelName+"/"+a.id),c.path("/"+a.modelName)},a.isCancelDisabled=function(){return"function"==typeof a.disableFunctions.isCancelDisabled?a.disableFunctions.isCancelDisabled(a.record,n,a.myForm):angular.equals(n,a.record)},a.isSaveDisabled=function(){return"function"==typeof a.disableFunctions.isSaveDisabled?a.disableFunctions.isSaveDisabled(a.record,n,a.myForm):a.myForm.$invalid||angular.equals(n,a.record)},a.isDeleteDisabled=function(){return"function"==typeof a.disableFunctions.isDeleteDisabled?a.disableFunctions.isDeleteDisabled(a.record,n,a.myForm):!1},a.isNewDisabled=function(){return"function"==typeof a.disableFunctions.isNewDisabled?a.disableFunctions.isNewDisabled(a.record,n,a.myForm):!1},a.disabledText=function(b){var c="";return a.isSaveDisabled&&(c="This button is only enabled when the form is complete and valid.  Make sure all required inputs are filled in. "+b),c},a.add=function(b){var c,d=b.field.name,e=d.split(".");c=a.record;for(var f=0,g=e.length;g>f;f++)c[e[f]]||(c[e[f]]=f===g-1?[]:{}),c=c[e[f]];c.push({})},a.remove=function(b,c){for(var d=b.$parent.field.name,e=d.split("."),f=a.record,g=0,h=e.length;h>g;g++)f=f[e[g]];f.splice(c,1)};var A=function(b,c,d){for(var e=0;e<b.length;e++){var f=b[e].name.slice(d);if(b[e].schema){if(c[f])for(var g=0;g<c[f].length;g++)c[f][g]=A(b[e].schema,c[f][g],d+1+f.length)}else{if(b[e].array&&"text"==b[e].type&&c[f])for(var h=0;h<c[f].length;h++)c[f][h]={x:c[f][h]};var i=a[q(b[e],"_ids")];i&&i.length>0&&c[f]?c[f]=l(b[e],c[f],a[q(b[e],"Options")],i):b[e].select2&&!b[e].select2.fngAjax&&c[f]&&a[b[e].select2.s2query].query({term:c[f],callback:function(a){a.results.length>0&&(c[f]=a.results[0])}})}}return c},B=function(b,c,d){for(var e=0;e<b.length;e++){var f=b[e].name.slice(d);if(b[e].schema){var g=a.getListData(c,f);if(g)for(var h=0;h<g.length;h++)g[h]=B(b[e].schema,g[h],d+1+f.length)}else{if(b[e].array&&"text"==b[e].type&&c[f])for(var i=0;i<c[f].length;i++)c[f][i]=c[f][i].x;var k=a[q(b[e],"_ids")];k&&k.length>0?j(f,c,function(c){return m(b[e],c,a[q(b[e],"Options")],k)}):b[e].select2&&(b[e].select2.fngAjax?c[f]&&(c[f]=c[f].id):c[f]=c[f]?c[f].text:"")}}return c},C=function(a,b,c,d){var e=b.indexOf(a);if(-1===e)throw new Error("convertIdToListValue: Invalid data - id "+a+" not found in "+b+" processing "+d);return c[e]},D=function(a,b,c,d){var e=_.isObject(a)?a.text:a,f=b.indexOf(e);if(-1===f)throw new Error("convertListValueToId: Invalid data - value "+e+" not found in "+b+" processing "+d);return c[f]},E=function(b,c){var e=a[c.options]=[],f=a[c.ids]=[];d.get("api/schema/"+b,{cache:!0}).success(function(a){var g=[];x("Lookup "+b,a,null,g,"",!1),d.get("api/"+b,{cache:!0}).success(function(a){if(a){for(var b=0;b<a.length;b++){for(var d="",h=0;h<g.length;h++)d+=a[b][g[h].name]+" ";d=d.trim();var i=_.sortedIndex(e,d);e.splice(i,0,d),f.splice(i,0,a[b]._id)}F(c)}})})},F=function(b){if(!(b.select2&&angular.equals(n[b.name],a.record[b.name].text)||angular.equals(n[b.name],a.record[b.name])))throw new Error("Cannot convert lookup values in changed record");j(b.name,n,function(c){return l(b,c,a[q(b,"Options")],a[q(b,"_ids")])}),a.record=angular.copy(n)};a.openSelect2=function(a){$("#"+$(a.currentTarget).data("select2-open")).select2("open")}}]),formsAngular.controller("ModelCtrl",["$scope","$http","$location",function(a,b,c){a.models=[],b.get("api/models").success(function(b){a.models=b}).error(function(){c.path("/404")})}]),formsAngular.controller("NavCtrl",["$scope","$location","$filter","$locationParse","$controller",function(a,b,c,d,e){function f(b,c){var d,f={};b+="Ctrl",f.$scope=a.scopes[c]=a.$new();try{e(b,f),d=a.routing.newRecord?"creating":a.routing.id?"editing":"listing",angular.forEach(a.scopes[c].contextMenu,function(b){b[d]&&a.items.push(b)})}catch(g){}}a.items=[],a.$on("$locationChangeSuccess",function(){a.routing=d(b.$$path),a.items=[],a.routing.modelName&&(angular.forEach(a.scopes,function(a){a.$destroy()}),a.scopes=[],a.contextMenu=c("titleCase")(a.routing.modelName,!0),f(a.contextMenu,0),a.routing.formName&&f(a.contextMenu+c("titleCase")(a.routing.formName,!0),1))}),a.doClick=function(b){var c=a.items[b].args||[],d=a.items[b].fn;switch(c.length){case 0:return d();case 1:return d(c[0]);case 2:return d(c[0],c[1]);case 3:return d(c[0],c[1],c[2]);case 4:return d(c[0],c[1],c[2],c[3])}}}]),formsAngular.controller("SearchCtrl",["$scope","$http",function(a,b){a.results=[],a.moreCount=0,a.$watch("searchTarget",function(c){c&&c.length>0?b.get("api/search?q="+c).success(function(b){a.results=b.results,a.moreCount=b.moreCount,a.errorClass=0===a.results.length?"error":""}).error(function(){console.log("Error in searchbox.js")}):(a.errorClass="",a.results=[])},!0),a.$on("$routeChangeStart",function(){a.searchTarget=""})}]),angular.module("fng.ui.bootstrap",["fng.ui.bootstrap.tpls","fng.ui.bootstrap.dropdownToggle","fng.ui.bootstrap.tabs"]),angular.module("fng.ui.bootstrap.tpls",["template/tabs/pane.html","template/tabs/tabs.html"]),angular.module("fng.ui.bootstrap.dropdownToggle",[]).directive("dropdownToggle",["$document","$location","$window",function(a){var b=null,c=angular.noop;return{restrict:"CA",link:function(d,e){d.$watch("$location.path",function(){c()}),e.parent().bind("click",function(){c()}),e.bind("click",function(d){d.preventDefault(),d.stopPropagation();var f=e===b;b&&c(),f||(e.parent().addClass("open"),b=e,c=function(d){d&&(d.preventDefault(),d.stopPropagation()),a.unbind("click",c),e.parent().removeClass("open"),c=angular.noop,b=null},a.bind("click",c))})}}}]),angular.module("fng.ui.bootstrap.tabs",[]).controller("TabsController",["$scope","$element",function(a){var b=a.panes=[];this.select=a.select=function(a){angular.forEach(b,function(a){a.selected=!1}),a.selected=!0},this.addPane=function(c){b.length||a.select(c),b.push(c)},this.removePane=function(c){var d=b.indexOf(c);b.splice(d,1),c.selected&&b.length>0&&a.select(b[d<b.length?d:d-1])}}]).directive("tabs",function(){return{restrict:"EA",transclude:!0,scope:{},controller:"TabsController",templateUrl:"template/tabs/tabs.html",replace:!0}}).directive("pane",["$parse",function(a){return{require:"^tabs",restrict:"EA",transclude:!0,scope:{heading:"@"},link:function(b,c,d,e){var f,g;b.selected=!1,d.active&&(f=a(d.active),g=f.assign,b.$watch(function(){return f(b.$parent)},function(a){b.selected=a}),b.selected=f?f(b.$parent):!1),b.$watch("selected",function(a){a&&e.select(b),g&&g(b.$parent,a)}),e.addPane(b),b.$on("$destroy",function(){e.removePane(b)})},templateUrl:"template/tabs/pane.html",replace:!0}}]),angular.module("template/tabs/pane.html",[]).run(["$templateCache",function(a){a.put("template/tabs/pane.html",'<div class="tab-pane" ng-class="{active: selected}" ng-show="selected" ng-transclude></div>')}]),angular.module("template/tabs/tabs.html",[]).run(["$templateCache",function(a){a.put("template/tabs/tabs.html",'<div class="tabbable">  <ul class="nav nav-tabs">    <li ng-repeat="pane in panes" ng-class="{active:pane.selected}">      <a ng-click="select(pane)">{{pane.heading}}</a>    </li>  </ul>  <div class="tab-content" ng-transclude></div></div>')}]),formsAngular.directive("formButtons",["$compile",function(a){return{restrict:"A",compile:function(){return function(b,c){var d='<div class="btn-group pull-right"><button id="saveButton" class="btn btn-mini btn-primary form-btn" ng-click="save()" ng-disabled="isSaveDisabled()"><i class="icon-ok"></i> Save</button><button id="cancelButton" class="btn btn-mini btn-warning form-btn" ng-click="cancel()" ng-disabled="isCancelDisabled()"><i class="icon-remove"></i> Cancel</button></div><div class="btn-group pull-right"><button id="newButton" class="btn btn-mini btn-success form-btn" ng-click="new()" ng-disabled="isNewDisabled()"><i class="icon-plus"></i> New</button><button id="deleteButton" class="btn btn-mini btn-danger form-btn" ng-click="delete()" ng-disabled="isDeleteDisabled()"><i class="icon-minus"></i> Delete</button></div>';c.replaceWith(a(d)(b))}}}}]),formsAngular.directive("formInput",["$compile",function(a){return{restrict:"E",replace:!0,priority:1,compile:function(){return function(b,c,d){b.$watch(d.formInput,function(){var e=function(a,e,f,g){var i="",j="";if(!e)if(-1!=a.name.indexOf(".")&&-1!=c[0].outerHTML.indexOf('schema="true"')){var k=a.name,l=k.lastIndexOf(".");e="record."+k.slice(0,l)+"."+b.$parent.$index+"."+k.slice(l+1),g=e.replace(/\./g,"-")}else e=(d.model||"record")+"."+a.name,0===b.$index&&(i="autofocus ");var m,n=f||a.required?" required":"",o=a.readonly?" readonly":"";if("select"===a.type)a.placeHolder&&(j='data-placeholder="'+a.placeHolder+'" '),a.select2&&a.select2.fngAjax?(m='<div class="input-append">',m+='<input ui-select2="'+a.select2.fngAjax+'" '+i+j+'ng-model="'+e+'" id="'+g+'" name="'+g+'" class="fng-select2">',m+='<button class="btn" type="button" data-select2-open="'+g+'" ng-click="openSelect2($event)"><i class="icon-search"></i></button>',m+="</div>"):a.select2?m='<input ui-select2="'+a.select2.s2query+'" '+i+j+'ng-model="'+e+'" id="'+g+'" name="'+g+'" class="fng-select2">':(m="<select "+i+'ng-model="'+e+'" id="'+g+'" name="'+g+'">',f||(m+="<option></option>"),m+='<option ng-repeat="option in '+a.options+'">{{option}}</option>',m+="</select>");else if("link"===a.type)m='<a ng-href="/#/'+a.ref+"/{{ "+e+'}}/edit">'+a.linkText+"</a>";else{var p=i+(a.add?a.add:"")+(a.placeHolder?'placeholder="'+a.placeHolder+'" ':"")+'ng-model="'+e+'"'+(g?' id="'+g+'" name="'+g+'"':"")+n+o+" ";m="textarea"==a.type?"<textarea "+p+(a.rows?'rows = "'+a.rows+'" ':"")+" />":"<input "+p+'type="'+h.type+'" />'}return a.helpInline&&(m+='<span class="help-inline">'+a.helpInline+"</span>"),a.help&&(m+='<span class="help-block">'+a.help+"</span>"),m},f=function(a,b){var c="";return(""!==a.label||b)&&(c='<label class="control-label" for="'+a.id+'">'+a.label+(b||"")+"</label>"),c},g=function(a){var c='<div class="control-group" id="cg_'+a.id+'">';if(a.schema){var g;g=b.formSchema[b.$index]&&a.id===b.formSchema[b.$index].id?"field in formSchema["+b.$index+"].schema":"field in panes["+b.$parent.$index+"].content["+b.$index+"].schema",c+='<div class="schema-head well">'+a.label+"</div>"+'<div class="sub-doc well" id="'+a.id+'List" ng-subdoc-repeat="subDoc in record.'+a.name+'">'+'<div class="row-fluid">'+'<div class="pull-left">'+'<form-input ng-repeat="'+g+'" info="{{field}}" schema="true"></form-input>'+"</div>",a.noRemove||(c+='<div class="pull-left sub-doc-btns"><button id="remove_'+a.id+'_btn" class="btn btn-mini form-btn" ng-click="remove(this,$index)">'+'<i class="icon-minus"></i> Remove'+"</button>"+"</div> "),c+='</div></div><div class = "schema-foot well">',a.noAdd||(c+='<button id="add_'+a.id+'_btn" class="btn btn-mini form-btn" ng-click="add(this)">'+'<i class="icon-plus"></i> Add'+"</button>"),c+="</div>"}else c+=a.array?f(a,' <i id="add_'+a.id+' " ng-click="add(this)" class="icon-plus-sign"></i>')+'<div class="controls" id="'+a.id+'List" ng-repeat="arrayItem in record.'+a.name+'">'+e(a,"arrayItem.x",!0,null)+'<i ng-click="remove(this,$index)" class="icon-minus-sign"></i>'+"</div>":f(a)+'<div class="controls">'+e(a,null,d.required,a.id)+"</div>";return c+="</div>"},h=JSON.parse(d.info);if(h.directive){for(var i="<"+h.directive,j=c[0],k=0;k<j.attributes.length;k++){var l=j.attributes[k];switch(l.nodeName){case"ng-repeat":break;case"class":var m=l.nodeValue.replace("ng-scope","");m.length>0&&(i+=' class="'+m+'"');break;case"info":var n=JSON.parse(l.nodeValue);delete n.directive,i+=' info="'+JSON.stringify(n).replace(/\"/g,"&quot;")+'"';break;default:i+=" "+l.nodeName+'="'+l.nodeValue+'"'}}i+="></"+h.directive+">",c.replaceWith(a(i)(b))}else{var o=g(h);c.replaceWith(a(o)(b))}b.updateDataDependentDisplay&&b.updateDataDependentDisplay(b.record,null,!0)})}}}}]),formsAngular.directive("ngSubdocRepeat",[function(){return{transclude:"element",priority:1e3,terminal:!0,compile:function(a,b,c){return function(a,b,d){var e,f,g,h,i=d.ngSubdocRepeat,j=i.match(/^\s*(.+)\s+in\s+(.*)\s*$/);if(!j)throw Error("Expected ngSubdocRepeat in form of '_item_ in _collection_' but got '"+i+"'.");if(e=j[1],f=j[2],j=e.match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/),!j)throw Error("'item' in 'item in collection' should be identifier or (key, value) but got '"+e+"'.");g=j[3]||j[1],h=j[2];var k=[];a.$watch(function(a){var d,e,i,j,l,m,n,o,p=a.$eval(f),q=b,r=[];if(angular.isArray(p))n=p||[];else{n=[];for(l in p)p.hasOwnProperty(l)&&"$"!=l.charAt(0)&&n.push(l);n.sort()}for(i=n.length,d=0,e=n.length;e>d;d++)l=p===n?d:n[d],m=p[l],o=k.shift(),o?(j=o.scope,r.push(o),q=o.element):j=a.$new(),j[g]=m,h&&(j[h]=l),j.$index=d,j.$first=0===d,j.$last=d===i-1,j.$middle=!(j.$first||j.$last),o||c(j,function(a){q.after(a),o={scope:j,element:q=a,index:d},r.push(o)});for(var s=0;s<k.length;s++)k[s].element.remove(),k[s].scope.$destroy();k=r})}}}}]),formsAngular.filter("titleCase",[function(){return function(a,b){var c=a.replace(/(_|\.)/g," ").replace(/[A-Z]/g," $&").replace(/\w\S*/g,function(a){return a.charAt(0).toUpperCase()+a.substr(1).toLowerCase()});return b&&(c=c.replace(/\s/g,"")),c}}]),formsAngular.factory("$data",[function(){var a={record:{},disableFunctions:{}};return a}]),formsAngular.factory("$locationParse",[function(){var a=null,b={};return function(c){if(c!==a){a=c;var d=c.split("/"),e=d.length;if(2==e&&"index"==d[1])b={index:!0};else{b={newRecord:!1},b.modelName=d[1];var f=d[e-1];"new"===f?(b.newRecord=!0,e--):"edit"===f&&(e-=2,b.id=d[e]),e>2&&(b.formName=d[2])}}return b}}]);<commit_msg>min file cacth up (again)<commit_after>/*! forms-angular 2013-07-09 */
"use strict";var formsAngular=angular.module("formsAngular",["ui.select2","ui.date","fng.ui.bootstrap"]);formsAngular.value("ui.config",{date:{dateFormat:"dd/mm/yy"}}),formsAngular.controller("BaseCtrl",["$scope","$routeParams","$location","$http","$filter","$data","$locationParse",function(a,b,c,d,e,f,g){function h(a,b,c){var d="#"+(c?"cg_":"")+b;a?$(d).removeClass(o):$(d).addClass(o)}function i(a){var b=a.split("."),c=[b[0]];return b.length>1&&c.push(b.slice(1).join(".")),c}function j(a,b,c){var d=i(a);if(d.length>1)k(d[1],b[d[0]],c);else if(b[d[0]]){var e=b[d[0]];b[d[0]]=c("Object"==typeof e?e.x:e)}}function k(a,b,c){if(void 0!==b)if($.isArray(b))for(var d=0;d<b.length;d++)j(a,b[d],c);else j(a,b,c)}function l(a,b,c,d){if(a.array){for(var e=[],f=0;f<b.length;f++)e.push({x:C(b[f],d,c,a.name)});return e}return C(b,d,c,a.name)}function m(a,b,c,d){if(a.array){for(var e=[],f=0;f<b.length;f++)e.push(D(b[f].x,c,d,a.name));return e}return D(b,c,d,a.name)}var n={},o="fng-invalid-required",p=f;a.record=p.record,a.disableFunctions=p.disableFunctions,a.formSchema=[],a.panes=[],a.listSchema=[],a.recordList=[],a.dataDependencies={},a.select2List=[],angular.extend(a,g(c.$$path)),a.formPlusSlash=a.formName?a.formName+"/":"",a.modelNameDisplay=e("titleCase")(a.modelName);var q=function(a,b){return a.id.replace(/\./g,"_")+b},r=function(b,e,f){var g;if(e.caster&&(b.array=!0,e=e.caster,$.extend(f,e.options)),"String"==e.instance)f.enum?(b.type="select",f.required&&(a.$watch("record."+b.name,function(a){h(a,b.id,b.select2)},!0),setTimeout(function(){h(a.record[b.name],b.id,b.select2)},0)),b.select2?(a["select2"+b.name]={allowClear:!f.required,initSelection:function(a,b){var c=a.val(),d={id:c,text:c};b(d)},query:function(a){for(var b={results:[]},c=a.term.toUpperCase(),d=0;d<f.enum.length;d++)-1!==f.enum[d].toUpperCase().indexOf(c)&&b.results.push({id:d,text:f.enum[d]});a.callback(b)}},_.extend(a["select2"+b.name],b.select2),b.select2.s2query="select2"+b.name,a.select2List.push(b.name)):(b.options=q(b,"Options"),a[b.options]=f.enum)):b.type||(b.type="text");else if("ObjectID"==e.instance)b.ref=f.ref,b.link&&b.link.linkOnly?(b.type="link",b.linkText=b.link.text,delete b.link):(b.type="select",b.select2?(a.select2List.push(b.name),b.select2.fngAjax?(g="ajax"+b.name.replace(/\./g,""),a[g]={allowClear:!f.required,minimumInputLength:2,initSelection:function(a,e){d.get("api/"+f.ref+"/"+a.val()+"/list").success(function(d){d.success===!1&&c.path("/404");var f={id:a.val(),text:d.list};n[b.name]=f,e(f)}).error(function(){c.path("/404")})},ajax:{url:"/api/search/"+f.ref,data:function(a,b){return{q:a,page_limit:10,page:b}},results:function(a){return{results:a.results,more:a.moreCount>0}}}},_.extend(a[g],b.select2),b.select2.fngAjax=g):(1==b.select2&&(b.select2={}),a["select2"+b.name]={allowClear:!f.required,initSelection:function(c,d){var e,f=c.val();e=a[b.options].length>0?D(f,a[b.options],a[b.ids],b.name):f;var g={id:e,text:f};d(g)},query:function(c){for(var d={results:[]},e=c.term.toUpperCase(),f=0;f<a[b.options].length;f++)-1!==a[b.options][f].toUpperCase().indexOf(e)&&d.results.push({id:a[b.ids][f],text:a[b.options][f]});c.callback(d)}},_.extend(a["select2"+b.name],b.select2),b.select2.s2query="select2"+b.name,a.select2List.push(b.name),b.options=q(b,"Options"),b.ids=q(b,"_ids"),E(f.ref,b))):(b.options=q(b,"Options"),b.ids=q(b,"_ids"),E(f.ref,b)));else if("Date"==e.instance)b.type="text",b.add="ui-date ui-date-format ";else if("boolean"==e.instance)b.type="checkbox";else{if("Number"!=e.instance)throw new Error("Field "+b.name+" is of unsupported type "+e.instance);b.type="number"}return f.required&&(b.required=!0),f.readonly&&(b.readonly=!0),b},s=function(a,b,c){return b.name=c+a,b.id=b.id||"f_"+c+a,b.label=null==(b.hasOwnProperty("label")&&b.label)?"":b.label||e("titleCase")(a),b},t=function(a,b,c){var d=b||{hidden:!0};d.hidden||("object"==typeof d?(d.name=c,a.push(d)):a.push({name:c}))},u=function(a,b,c,d){if(c){for(var e=0,f=c.length;f>e;e++)if("text"==c[e].type){b.push({name:c[e].name});break}0===b.length&&0!==c.length&&b.push({name:c[0].name})}if(0===b.length){for(var g in d)if("_id"!==g&&d.hasOwnProperty(g)){b.push({name:g});break}if(0===b.length)throw new Error("Unable to generate a title for "+a)}},v=function(b,c){function d(b){var d=b;return"string"==typeof b&&"$"===b.slice(0,1)&&(d=a.getListData(c,b.slice(1))),d}var e,f=d(b.lhs),g=d(b.rhs);switch(b.comp){case"eq":e=f===g;break;case"ne":e=f!==g;break;default:throw new Error("Unsupported comparator "+b.comp)}return e},w=function(b,c){function d(b){if("string"==typeof b&&"$"===b.slice(0,1)){var d=b.slice(1),f=a.dataDependencies[d]||[];f.push(c),a.dataDependencies[d]=f,e+=1}}var e=0,f=!0;return b&&(d(b.lhs),d(b.rhs),0!==e||v(b)||(f=!1)),f};a.getListData=function(b,c){for(var d=c.split("."),e=0;e<d.length;e++)void 0!==b&&(b=b[d[e]]);return b&&-1!==a.select2List.indexOf(d[e-1])&&(b=b.text),void 0===b&&(b=""),b},a.updateDataDependentDisplay=function(b,c,d){for(var e in a.dataDependencies)if(a.dataDependencies.hasOwnProperty(e)&&(d||b[e]!=c[e]))for(var f=a.dataDependencies[e],g=0;g<f.length;g+=1)for(var h=f[g],i=0;i<a.formSchema.length;i+=1)if(a.formSchema[i].id===h){var j=$("#cg_"+h);v(a.formSchema[i].showIf,b)?j.show():j.hide()}};var x=function(b,c,d,e,f,g){function h(b,c){var d=angular.copy(b),e=_.find(a.panes,function(a){return a.title===d});if(!e){var f=!1;if(0===a.panes.length)if(a.formSchema.length>0){a.panes.push({title:"Main",content:[],active:!0}),e=a.panes[0];for(var g=0;g<a.formSchema.length;g++)e.content.push(a.formSchema[g])}else f=!0;e=a.panes[a.panes.push({title:d,content:[],active:f})-1]}e.content.push(c)}for(var i in c)if("_id"!==i&&c.hasOwnProperty(i)){var j=c[i],k=j.options||{},l=k.form||{};if(!l.hidden)if(j.schema){if(g&&d){var m=[];x("Nested "+i,j.schema,m,null,i+".",!0);var n=s(i,l,f);n.schema=m,l.pane&&h(l.pane,n),d.push(n)}}else{if(d){var o=s(i,l,f);if(w(o.showIf,o.id)){var p=r(o,j,k);p.pane&&h(p.pane,p),d.push(p)}}e&&t(e,k.list,i)}}e&&0===e.length&&u(b,e,d,c)};d.get("api/schema/"+a.modelName+(a.formName?"/"+a.formName:""),{cache:!0}).success(function(e){if(x("Main "+a.modelName,e,a.formSchema,a.listSchema,"",!0),a.id||a.newRecord)a.$watch("record",function(b,c){a.updateDataDependentDisplay(b,c,!1)},!0),a.id?d.get("api/"+a.modelName+"/"+a.id).success(function(b){b.success===!1&&c.path("/404"),n=A(a.formSchema,b,0),a.cancel()}).error(function(){c.path("/404")}):(n={},a.cancel());else{var f="?",g="";b.f&&(g+=f+"f="+b.f,f="&"),b.a&&(g+=f+"a="+b.a),d.get("api/"+a.modelName+g).success(function(b){a.recordList=b}).error(function(){c.path("/404")})}}).error(function(){c.path("/404")}),a.cancel=function(){var b;for(b in a.record)a.record.hasOwnProperty(b)&&delete a.record[b];for(b in n)n.hasOwnProperty(b)&&(a.record[b]=n[b]);a.dismissError()};var y=function(a,b){if(-1!==[200,400].indexOf(b)){var c="";for(var d in a.errors)if(a.errors.hasOwnProperty(d)){switch(c+="<li><b>"+e("titleCase")(d)+": </b> ",a.errors[d].type){case"enum":c+="You need to select from the list of values";break;default:c+=a.errors[d].message}c+="</li>"}c=c.length>0?a.message+"<br /><ul>"+c+"</ul>":a.message||"Error!  Sorry - No further details available.",z(c)}else z(b+" "+JSON.stringify(a))},z=function(b,c){a.alertTitle=c?c:"Error!",a.errorMessage=b};a.dismissError=function(){delete a.errorMessage},a.save=function(b){b=b||{};var e=B(a.formSchema,angular.copy(a.record),0);a.record._id?d.post("api/"+a.modelName+"/"+a.id,e).success(function(c){c.success!==!1?b.redirect?window.location=b.redirect:(n=c,a.cancel()):z(c)}).error(y):d.post("api/"+a.modelName,e).success(function(d){d.success!==!1?b.redirect?window.location=b.redirect:c.path("/"+a.modelName+"/"+d._id+"/edit"):z(d)}).error(y)},a.new=function(){c.path("/"+a.modelName+"/new")},a.delete=function(){a.record._id&&d.delete("api/"+a.modelName+"/"+a.id),c.path("/"+a.modelName)},a.isCancelDisabled=function(){return"function"==typeof a.disableFunctions.isCancelDisabled?a.disableFunctions.isCancelDisabled(a.record,n,a.myForm):angular.equals(n,a.record)},a.isSaveDisabled=function(){return"function"==typeof a.disableFunctions.isSaveDisabled?a.disableFunctions.isSaveDisabled(a.record,n,a.myForm):a.myForm.$invalid||angular.equals(n,a.record)},a.isDeleteDisabled=function(){return"function"==typeof a.disableFunctions.isDeleteDisabled?a.disableFunctions.isDeleteDisabled(a.record,n,a.myForm):!1},a.isNewDisabled=function(){return"function"==typeof a.disableFunctions.isNewDisabled?a.disableFunctions.isNewDisabled(a.record,n,a.myForm):!1},a.disabledText=function(b){var c="";return a.isSaveDisabled&&(c="This button is only enabled when the form is complete and valid.  Make sure all required inputs are filled in. "+b),c},a.add=function(b){var c,d=b.field.name,e=d.split(".");c=a.record;for(var f=0,g=e.length;g>f;f++)c[e[f]]||(c[e[f]]=f===g-1?[]:{}),c=c[e[f]];c.push({})},a.remove=function(b,c){for(var d=b.$parent.field.name,e=d.split("."),f=a.record,g=0,h=e.length;h>g;g++)f=f[e[g]];f.splice(c,1)};var A=function(b,c,d){for(var e=0;e<b.length;e++){var f=b[e].name.slice(d);if(b[e].schema){if(c[f])for(var g=0;g<c[f].length;g++)c[f][g]=A(b[e].schema,c[f][g],d+1+f.length)}else{if(b[e].array&&"text"==b[e].type&&c[f])for(var h=0;h<c[f].length;h++)c[f][h]={x:c[f][h]};var i=a[q(b[e],"_ids")];i&&i.length>0&&c[f]?c[f]=l(b[e],c[f],a[q(b[e],"Options")],i):b[e].select2&&!b[e].select2.fngAjax&&c[f]&&a[b[e].select2.s2query].query({term:c[f],callback:function(a){a.results.length>0&&(c[f]=a.results[0])}})}}return c},B=function(b,c,d){for(var e=0;e<b.length;e++){var f=b[e].name.slice(d);if(b[e].schema){var g=a.getListData(c,f);if(g)for(var h=0;h<g.length;h++)g[h]=B(b[e].schema,g[h],d+1+f.length)}else{if(b[e].array&&"text"==b[e].type&&c[f])for(var i=0;i<c[f].length;i++)c[f][i]=c[f][i].x;var k=a[q(b[e],"_ids")];k&&k.length>0?j(f,c,function(c){return m(b[e],c,a[q(b[e],"Options")],k)}):b[e].select2&&(b[e].select2.fngAjax?c[f]&&(c[f]=c[f].id):c[f]=c[f]?c[f].text:"")}}return c},C=function(a,b,c,d){var e=b.indexOf(a);if(-1===e)throw new Error("convertIdToListValue: Invalid data - id "+a+" not found in "+b+" processing "+d);return c[e]},D=function(a,b,c,d){var e=_.isObject(a)?a.text:a,f=b.indexOf(e);if(-1===f)throw new Error("convertListValueToId: Invalid data - value "+e+" not found in "+b+" processing "+d);return c[f]},E=function(b,c){var e=a[c.options]=[],f=a[c.ids]=[];d.get("api/schema/"+b,{cache:!0}).success(function(a){var g=[];x("Lookup "+b,a,null,g,"",!1),d.get("api/"+b,{cache:!0}).success(function(a){if(a){for(var b=0;b<a.length;b++){for(var d="",h=0;h<g.length;h++)d+=a[b][g[h].name]+" ";d=d.trim();var i=_.sortedIndex(e,d);e.splice(i,0,d),f.splice(i,0,a[b]._id)}F(c)}})})},F=function(b){if(!(b.select2&&angular.equals(n[b.name],a.record[b.name].text)||angular.equals(n[b.name],a.record[b.name])))throw new Error("Cannot convert lookup values in changed record");j(b.name,n,function(c){return l(b,c,a[q(b,"Options")],a[q(b,"_ids")])}),a.record=angular.copy(n)};a.openSelect2=function(a){$("#"+$(a.currentTarget).data("select2-open")).select2("open")}}]),formsAngular.controller("ModelCtrl",["$scope","$http","$location",function(a,b,c){a.models=[],b.get("api/models").success(function(b){a.models=b}).error(function(){c.path("/404")})}]),formsAngular.controller("NavCtrl",["$scope","$location","$filter","$locationParse","$controller",function(a,b,c,d,e){function f(b,c){var d,f={};b+="Ctrl",f.$scope=a.scopes[c]=a.$new();try{e(b,f),d=a.routing.newRecord?"creating":a.routing.id?"editing":"listing",angular.forEach(a.scopes[c].contextMenu,function(b){b[d]&&a.items.push(b)})}catch(g){g.message==="Argument '"+b+"' is not a function, got undefined"||console.log("Unable to instantiate "+b+" - "+g.message)}}a.items=[],a.$on("$locationChangeSuccess",function(){a.routing=d(b.$$path),a.items=[],a.routing.modelName&&(angular.forEach(a.scopes,function(a){a.$destroy()}),a.scopes=[],a.contextMenu=c("titleCase")(a.routing.modelName,!0),f(a.contextMenu,0),a.routing.formName&&f(a.contextMenu+c("titleCase")(a.routing.formName,!0),1))}),a.doClick=function(b){var c=a.items[b].args||[],d=a.items[b].fn;switch(c.length){case 0:return d();case 1:return d(c[0]);case 2:return d(c[0],c[1]);case 3:return d(c[0],c[1],c[2]);case 4:return d(c[0],c[1],c[2],c[3])}}}]),formsAngular.controller("SearchCtrl",["$scope","$http",function(a,b){a.results=[],a.moreCount=0,a.$watch("searchTarget",function(c){c&&c.length>0?b.get("api/search?q="+c).success(function(b){a.results=b.results,a.moreCount=b.moreCount,a.errorClass=0===a.results.length?"error":""}).error(function(){console.log("Error in searchbox.js")}):(a.errorClass="",a.results=[])},!0),a.$on("$routeChangeStart",function(){a.searchTarget=""})}]),angular.module("fng.ui.bootstrap",["fng.ui.bootstrap.tpls","fng.ui.bootstrap.dropdownToggle","fng.ui.bootstrap.tabs"]),angular.module("fng.ui.bootstrap.tpls",["template/tabs/pane.html","template/tabs/tabs.html"]),angular.module("fng.ui.bootstrap.dropdownToggle",[]).directive("dropdownToggle",["$document","$location","$window",function(a){var b=null,c=angular.noop;return{restrict:"CA",link:function(d,e){d.$watch("$location.path",function(){c()}),e.parent().bind("click",function(){c()}),e.bind("click",function(d){d.preventDefault(),d.stopPropagation();var f=e===b;b&&c(),f||(e.parent().addClass("open"),b=e,c=function(d){d&&(d.preventDefault(),d.stopPropagation()),a.unbind("click",c),e.parent().removeClass("open"),c=angular.noop,b=null},a.bind("click",c))})}}}]),angular.module("fng.ui.bootstrap.tabs",[]).controller("TabsController",["$scope","$element",function(a){var b=a.panes=[];this.select=a.select=function(a){angular.forEach(b,function(a){a.selected=!1}),a.selected=!0},this.addPane=function(c){b.length||a.select(c),b.push(c)},this.removePane=function(c){var d=b.indexOf(c);b.splice(d,1),c.selected&&b.length>0&&a.select(b[d<b.length?d:d-1])}}]).directive("tabs",function(){return{restrict:"EA",transclude:!0,scope:{},controller:"TabsController",templateUrl:"template/tabs/tabs.html",replace:!0}}).directive("pane",["$parse",function(a){return{require:"^tabs",restrict:"EA",transclude:!0,scope:{heading:"@"},link:function(b,c,d,e){var f,g;b.selected=!1,d.active&&(f=a(d.active),g=f.assign,b.$watch(function(){return f(b.$parent)},function(a){b.selected=a}),b.selected=f?f(b.$parent):!1),b.$watch("selected",function(a){a&&e.select(b),g&&g(b.$parent,a)}),e.addPane(b),b.$on("$destroy",function(){e.removePane(b)})},templateUrl:"template/tabs/pane.html",replace:!0}}]),angular.module("template/tabs/pane.html",[]).run(["$templateCache",function(a){a.put("template/tabs/pane.html",'<div class="tab-pane" ng-class="{active: selected}" ng-show="selected" ng-transclude></div>')}]),angular.module("template/tabs/tabs.html",[]).run(["$templateCache",function(a){a.put("template/tabs/tabs.html",'<div class="tabbable">  <ul class="nav nav-tabs">    <li ng-repeat="pane in panes" ng-class="{active:pane.selected}">      <a ng-click="select(pane)">{{pane.heading}}</a>    </li>  </ul>  <div class="tab-content" ng-transclude></div></div>')}]),formsAngular.directive("formButtons",["$compile",function(a){return{restrict:"A",compile:function(){return function(b,c){var d='<div class="btn-group pull-right"><button id="saveButton" class="btn btn-mini btn-primary form-btn" ng-click="save()" ng-disabled="isSaveDisabled()"><i class="icon-ok"></i> Save</button><button id="cancelButton" class="btn btn-mini btn-warning form-btn" ng-click="cancel()" ng-disabled="isCancelDisabled()"><i class="icon-remove"></i> Cancel</button></div><div class="btn-group pull-right"><button id="newButton" class="btn btn-mini btn-success form-btn" ng-click="new()" ng-disabled="isNewDisabled()"><i class="icon-plus"></i> New</button><button id="deleteButton" class="btn btn-mini btn-danger form-btn" ng-click="delete()" ng-disabled="isDeleteDisabled()"><i class="icon-minus"></i> Delete</button></div>';c.replaceWith(a(d)(b))}}}}]),formsAngular.directive("formInput",["$compile",function(a){return{restrict:"E",replace:!0,priority:1,compile:function(){return function(b,c,d){b.$watch(d.formInput,function(){var e=function(a,e,f,g){var i="";if(!e)if(-1!=a.name.indexOf(".")&&-1!=c[0].outerHTML.indexOf('schema="true"')){var j=a.name,k=j.lastIndexOf(".");e="record."+j.slice(0,k)+"."+b.$parent.$index+"."+j.slice(k+1),g=e.replace(/\./g,"-")}else e=(d.model||"record")+"."+a.name,0===b.$index&&(i="autofocus ");var l,m,n=f||a.required?" required":"",o=a.readonly?" readonly":"",m=i+'ng-model="'+e+'"'+(g?' id="'+g+'" name="'+g+'" ':" ")+(a.placeHolder?'placeholder="'+a.placeHolder+'" ':"");return"select"===a.type?a.select2?(m+='class="fng-select2'+(a.size?"input-"+a.size:"")+'"',a.select2.fngAjax?(l='<div class="input-append">',l+='<input ui-select2="'+a.select2.fngAjax+'" '+m+">",l+='<button class="btn" type="button" data-select2-open="'+g+'" ng-click="openSelect2($event)"><i class="icon-search"></i></button>',l+="</div>"):a.select2&&(l='<input ui-select2="'+a.select2.s2query+'" '+m+">")):(l="<select "+m+(a.size?'class="input-'+a.size+'" ':"")+">",f||(l+="<option></option>"),l+='<option ng-repeat="option in '+a.options+'">{{option}}</option>',l+="</select>"):"link"===a.type?l='<a ng-href="/#/'+a.ref+"/{{ "+e+'}}/edit">'+a.linkText+"</a>":(m+=(a.size?'class="input-'+a.size+'" ':"")+(a.add?a.add:"")+'ng-model="'+e+'"'+(g?' id="'+g+'" name="'+g+'"':"")+n+o+" ",l="textarea"==a.type?"<textarea "+m+(a.rows?'rows = "'+a.rows+'" ':"")+" />":"<input "+m+'type="'+h.type+'" />'),a.helpInline&&(l+='<span class="help-inline">'+a.helpInline+"</span>"),a.help&&(l+='<span class="help-block">'+a.help+"</span>"),l},f=function(a,b){var c="";return(""!==a.label||b)&&(c='<label class="control-label" for="'+a.id+'">'+a.label+(b||"")+"</label>"),c},g=function(a){var c='<div class="control-group" id="cg_'+a.id+'">';if(a.schema){var g;g=b.formSchema[b.$index]&&a.id===b.formSchema[b.$index].id?"field in formSchema["+b.$index+"].schema":"field in panes["+b.$parent.$index+"].content["+b.$index+"].schema",c+='<div class="schema-head well">'+a.label+"</div>"+'<div class="sub-doc well" id="'+a.id+'List" ng-subdoc-repeat="subDoc in record.'+a.name+'">'+'<div class="row-fluid">'+'<div class="pull-left">'+'<form-input ng-repeat="'+g+'" info="{{field}}" schema="true"></form-input>'+"</div>",a.noRemove||(c+='<div class="pull-left sub-doc-btns"><button id="remove_'+a.id+'_btn" class="btn btn-mini form-btn" ng-click="remove(this,$index)">'+'<i class="icon-minus"></i> Remove'+"</button>"+"</div> "),c+='</div></div><div class = "schema-foot well">',a.noAdd||(c+='<button id="add_'+a.id+'_btn" class="btn btn-mini form-btn" ng-click="add(this)">'+'<i class="icon-plus"></i> Add'+"</button>"),c+="</div>"}else c+=a.array?f(a,' <i id="add_'+a.id+' " ng-click="add(this)" class="icon-plus-sign"></i>')+'<div class="controls" id="'+a.id+'List" ng-repeat="arrayItem in record.'+a.name+'">'+e(a,"arrayItem.x",!0,null)+'<i ng-click="remove(this,$index)" class="icon-minus-sign"></i>'+"</div>":f(a)+'<div class="controls">'+e(a,null,d.required,a.id)+"</div>";return c+="</div>"},h=JSON.parse(d.info);if(h.directive){for(var i="<"+h.directive,j=c[0],k=0;k<j.attributes.length;k++){var l=j.attributes[k];switch(l.nodeName){case"ng-repeat":break;case"class":var m=l.nodeValue.replace("ng-scope","");m.length>0&&(i+=' class="'+m+'"');break;case"info":var n=JSON.parse(l.nodeValue);delete n.directive,i+=' info="'+JSON.stringify(n).replace(/\"/g,"&quot;")+'"';break;default:i+=" "+l.nodeName+'="'+l.nodeValue+'"'}}i+="></"+h.directive+">",c.replaceWith(a(i)(b))}else{var o=g(h);c.replaceWith(a(o)(b))}b.updateDataDependentDisplay&&b.updateDataDependentDisplay(b.record,null,!0)})}}}}]),formsAngular.directive("ngSubdocRepeat",[function(){return{transclude:"element",priority:1e3,terminal:!0,compile:function(a,b,c){return function(a,b,d){var e,f,g,h,i=d.ngSubdocRepeat,j=i.match(/^\s*(.+)\s+in\s+(.*)\s*$/);if(!j)throw Error("Expected ngSubdocRepeat in form of '_item_ in _collection_' but got '"+i+"'.");if(e=j[1],f=j[2],j=e.match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/),!j)throw Error("'item' in 'item in collection' should be identifier or (key, value) but got '"+e+"'.");g=j[3]||j[1],h=j[2];var k=[];a.$watch(function(a){var d,e,i,j,l,m,n,o,p=a.$eval(f),q=b,r=[];if(angular.isArray(p))n=p||[];else{n=[];for(l in p)p.hasOwnProperty(l)&&"$"!=l.charAt(0)&&n.push(l);n.sort()}for(i=n.length,d=0,e=n.length;e>d;d++)l=p===n?d:n[d],m=p[l],o=k.shift(),o?(j=o.scope,r.push(o),q=o.element):j=a.$new(),j[g]=m,h&&(j[h]=l),j.$index=d,j.$first=0===d,j.$last=d===i-1,j.$middle=!(j.$first||j.$last),o||c(j,function(a){q.after(a),o={scope:j,element:q=a,index:d},r.push(o)});for(var s=0;s<k.length;s++)k[s].element.remove(),k[s].scope.$destroy();k=r})}}}}]),formsAngular.filter("titleCase",[function(){return function(a,b){var c=a.replace(/(_|\.)/g," ").replace(/[A-Z]/g," $&").replace(/\w\S*/g,function(a){return a.charAt(0).toUpperCase()+a.substr(1).toLowerCase()});return b&&(c=c.replace(/\s/g,"")),c}}]),formsAngular.factory("$data",[function(){var a={record:{},disableFunctions:{}};return a}]),formsAngular.factory("$locationParse",[function(){var a=null,b={};return function(c){if(c!==a){a=c;var d=c.split("/"),e=d.length;if(2==e&&"index"==d[1])b={index:!0};else{b={newRecord:!1},b.modelName=d[1];var f=d[e-1];"new"===f?(b.newRecord=!0,e--):"edit"===f&&(e-=2,b.id=d[e]),e>2&&(b.formName=d[2])}}return b}}]);
{'fraction_non_alphanumeric': 0.32387888974484674, 'fraction_numerical': 0.012115694376356888, 'mean_word_length': 12.262538699690403, 'pattern_counts': {'":': 39, '<': 237, '<?xml version=': 0, '>': 231, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6788891', 'n_tokens_mistral': 18606, 'n_tokens_neox': 18510, 'n_words': 953}