-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmetawidget-angular.min.js
18 lines (17 loc) · 8.76 KB
/
metawidget-angular.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Metawidget 4.2 minified
//
// This file is dual licensed under both the LGPL
// (http://www.gnu.org/licenses/lgpl-2.1.html) and the EPL
// (http://www.eclipse.org/org/documents/epl-v10.php). As a
// recipient of Metawidget, you may choose to receive it under either
// the LGPL or the EPL.
//
// Commercial licenses are also available. See http://metawidget.org
// for details.
//
// Author: Richard Kennard (http://kennardconsulting.com)
var metawidget=metawidget||{};(function(){var b=["$compile","$parse",function(c,d){return{restrict:"E",scope:{ngModel:"=",readOnly:"=",config:"=",ngShow:"=",ngHide:"=",configs:"&"},transclude:true,compile:function(g,f,e){return function(r,k,p){var q=new metawidget.angular.AngularMetawidget(k,p,e,r,c,d);var j=undefined;m();var o=r.$watch("config",function(t,s){if(t!==s){q.configure(t);m()}});var h=r.$watch("ngModel",function(s){if(s!==j&&typeof(s)==="object"){q.invalidateInspection();m()}});var i=r.$watch("readOnly",function(s){if(s!==q.readOnly){m()}});var n=r.$watch("ngShow",function(t,s){if(t!==s){m()}});var l=r.$watch("ngHide",function(t,s){if(t!==s){m()}});k.on("$destroy",function(){o();h();i();n();l()});function m(){if(r.$eval("ngShow")===false||r.$eval("ngHide")===true){return}j=r.$eval("ngModel");q.path=p.ngModel;q.toInspect=r.$parent.$eval(metawidget.util.splitPath(q.path).type);q.readOnly=r.$eval("readOnly");q.buildWidgets()}}}}}];var a=angular.module("metawidget",[]);a.directive("metawidget",b);a.directive("mwMetawidget",b);metawidget.angular=metawidget.angular||{};metawidget.angular.AngularMetawidget=function(g,d,c,h,f,i){if(!(this instanceof metawidget.angular.AngularMetawidget)){throw new Error("Constructor called as a function")}var e=new metawidget.Pipeline(g[0]);e._superLayoutWidget=e.layoutWidget;e.layoutWidget=function(n,k,m,l,o){e._superLayoutWidget.call(this,n,k,m,l,o);if(n.overridden===undefined){f(n)(h.$parent)}};var j=undefined;this.invalidateInspection=function(){j=undefined};e.inspector=new metawidget.inspector.PropertyTypeInspector();e.inspectionResultProcessors=[new metawidget.angular.inspectionresultprocessor.AngularInspectionResultProcessor(h.$parent)];e.widgetBuilder=new metawidget.widgetbuilder.CompositeWidgetBuilder([new metawidget.widgetbuilder.OverriddenWidgetBuilder(),new metawidget.widgetbuilder.ReadOnlyWidgetBuilder(),new metawidget.widgetbuilder.HtmlWidgetBuilder()]);e.widgetProcessors=[new metawidget.widgetprocessor.IdProcessor(),new metawidget.widgetprocessor.PlaceholderAttributeProcessor(),new metawidget.widgetprocessor.DisabledAttributeProcessor(),new metawidget.angular.widgetprocessor.AngularWidgetProcessor(i,h.$parent)];
e.layout=new metawidget.layout.HeadingTagLayoutDecorator(new metawidget.layout.TableLayout());this.configure=function(k){e.configure(k);this.invalidateInspection()};this.configure(h.$eval("config"));this.configure(h.configs());this.inspect=function(m,k,l){return e.inspect(m,k,l,this)};this.clearWidgets=function(){var k=angular.element(this.getElement());if(k.empty!==undefined){k.empty()}else{k.html("")}};this.buildWidgets=function(o){var k=c(h.$parent,function(p){return p});this.overriddenNodes=[];for(var l=0;l<k.length;l++){var n=k[l];if(n.nodeType===1&&(n.tagName!=="SPAN"||n.attributes.length>1)){this.overriddenNodes.push(n)}}if(o!==undefined){j=o}else{if(j===undefined){if(arguments.length>0){throw new Error("Calling buildWidgets( undefined ) may cause infinite loop. Check your argument, or pass no arguments instead")}var m=metawidget.util.splitPath(this.path);j=e.inspect(this.toInspect,m.type,m.names,this)}}g.children().remove();e.buildWidgets(j,this)};this.onEndBuild=function(){while(this.overriddenNodes.length>0){var l=this.overriddenNodes[0];this.overriddenNodes.splice(0,1);if(l.tagName==="FACET"){continue}var o={};var q,m;m=l.attributes.length;for(q=0;q<m;q++){var n=l.attributes[q];var p=d.$normalize(n.name).toLowerCase();if(p==="ngbind"||p==="ngmodel"){var r=metawidget.util.splitPath(n.value);var s=h.$parent.$eval(r.type);o=e.inspect(s,r.type,r.names,this);break}}if(o===undefined){o={section:""}}if(l.tagName==="STUB"){m=l.attributes.length;for(q=0;q<m;q++){var k=l.attributes[q];o[k.nodeName]=k.nodeValue}}e.layoutWidget(l,"property",o,e.element,this)}};this.getElement=function(){return e.element};this.buildNestedMetawidget=function(k,l){var n=metawidget.util.createElement(this,"metawidget");n.setAttribute("ng-model",metawidget.util.appendPath(k,this));if(metawidget.util.isTrueOrTrueString(k.readOnly)){n.setAttribute("read-only","true")}else{if(d.readOnly!==undefined){n.setAttribute("read-only",d.readOnly)}}h.$parent._nestedMetawidgetConfigId=h.$parent._nestedMetawidgetConfigId||0;
var o="_metawidgetConfig"+h.$parent._nestedMetawidgetConfigId++;h.$parent[o]=e;if(l!==undefined){var m="_metawidgetConfig"+h.$parent._nestedMetawidgetConfigId++;h.$parent[m]=l;n.setAttribute("configs","["+o+","+m+"]")}else{n.setAttribute("config",o)}return n}};metawidget.angular.inspectionresultprocessor=metawidget.angular.inspectionresultprocessor||{};metawidget.angular.inspectionresultprocessor.AngularInspectionResultProcessor=function(c){if(!(this instanceof metawidget.angular.inspectionresultprocessor.AngularInspectionResultProcessor)){throw new Error("Constructor called as a function")}this.processInspectionResult=function(f,i){function d(m,k){if(m!==k){for(var j=0,l=i._angularInspectionResultProcessor.length;j<l;j++){i._angularInspectionResultProcessor[j]()}i.invalidateInspection();i.buildWidgets()}}i._angularInspectionResultProcessor=i._angularInspectionResultProcessor||[];for(var e in f){var h=f[e];if(h instanceof Object){this.processInspectionResult(h,i);continue}if(h===undefined||h===null||h.slice===undefined){continue}if(h.length<4||h.slice(0,2)!=="{{"||h.slice(h.length-2,h.length)!=="}}"){continue}h=h.slice(2,h.length-2);f[e]=c.$eval(h)+"";var g=c.$watch(h,d);i._angularInspectionResultProcessor.push(g)}return f}};metawidget.angular.widgetprocessor=metawidget.angular.widgetprocessor||{};metawidget.angular.widgetprocessor.AngularWidgetProcessor=function(f,e){if(!(this instanceof metawidget.angular.widgetprocessor.AngularWidgetProcessor)){throw new Error("Constructor called as a function")}this.processWidget=function(k,p,j,o){var m=o.path;if(p!=="entity"){m=metawidget.util.appendPathWithName(m,j)}if(k.tagName==="OUTPUT"){if(!k.hasAttribute("ng-bind")){if(metawidget.util.isTrueOrTrueString(j.masked)){e.$parent.mwMaskedOutput=d;k.setAttribute("ng-bind","mwMaskedOutput("+m+")")}else{if(j.type==="array"){k.setAttribute("ng-bind",m+".join(', ')")}else{if(j.enumTitles!==undefined){e.$parent.mwLookupEnumTitle=e.$parent.mwLookupEnumTitle||{};e.$parent.mwLookupEnumTitle[m]=function(q){return metawidget.util.lookupEnumTitle(q,j["enum"],j.enumTitles)
};k.setAttribute("ng-bind",'mwLookupEnumTitle["'+m+'"]('+m+")")}else{if(j.type==="date"){k.setAttribute("ng-bind",m+"|date")}else{k.setAttribute("ng-bind",m)}}}}}}else{if(k.tagName==="INPUT"&&k.getAttribute("type")==="submit"){k.removeAttribute("ng-click")}else{if(k.tagName==="INPUT"&&k.getAttribute("type")==="button"){k.setAttribute("ng-click",m+"()")}else{if(j["enum"]!==undefined&&(j.type==="array"||j.componentType!==undefined)&&k.tagName==="DIV"){for(var l=0,i=k.childNodes.length;l<i;l++){var n=k.childNodes[l];if(n.tagName==="LABEL"&&n.childNodes.length===2){var h=n.childNodes[0];if(h.tagName==="INPUT"){if(h.getAttribute("type")==="radio"){h.setAttribute("ng-model",m);if(h.value===true||h.value==="true"){h.setAttribute("ng-value","true")}else{if(h.value===false||h.value==="false"){h.setAttribute("ng-value","false")}}}else{if(h.getAttribute("type")==="checkbox"){h.setAttribute("ng-checked",m+".indexOf('"+h.value+"')>=0");e.mwUpdateSelection=g;h.setAttribute("ng-click","mwUpdateSelection($event,'"+m+"')")}}}}}}else{if(k.tagName==="SELECT"){k.setAttribute("ng-model",m);if(j.type==="boolean"||j.type==="integer"||j.type==="number"){k.setAttribute("ng-change","mwChangeAsType('"+j.type+"','"+m+"')");e.mwChangeAsType=c;for(var l=0,i=k.childNodes.length;l<i;l++){var h=k.childNodes[l];if(h.tagName==="OPTION"&&h.value!==""){h.setAttribute("ng-selected",m+"=="+h.value)}}}}else{if(k.tagName==="INPUT"||k.tagName==="TEXTAREA"){k.setAttribute("ng-model",m)}}}}}}if(!metawidget.util.isTrueOrTrueString(j.readOnly)){if(j.required!==undefined){k.setAttribute("ng-required",j.required)}if(j.minLength!==undefined){k.setAttribute("ng-minlength",j.minLength)}if(j.maxLength!==undefined){k.setAttribute("ng-maxlength",j.maxLength)}}return k};function g(h,l){var j=e.$eval(l);if(j===undefined){j=[];f(l).assign(e,j)}var k=h.target;var i=j.indexOf(k.value);if(k.checked===true){if(i===-1){j.push(k.value)}return}if(i!==-1){j.splice(i,1)}}function d(h){if(h===undefined){return}return metawidget.util.fillString("*",h.length)
}function c(h,j){var i=f(j);if(h==="boolean"){i.assign(e,i(e)==="true");return}if(h==="integer"){i.assign(e,parseInt(i(e)));return}if(h==="number"){i.assign(e,parseFloat(i(e)));return}}}})();