pancakes-angular
Advanced tools
Comparing version 0.1.27 to 0.1.28
@@ -550,51 +550,54 @@ /** | ||
app.directive(directiveName, ['i18n', 'config', function (i18n, config) { | ||
return function (scope, element, attrs) { | ||
var originalValue = attrs[directiveName]; | ||
return { | ||
priority: 101, | ||
link: function linkFn(scope, element, attrs) { | ||
var originalValue = attrs[directiveName]; | ||
// if we are binding to the attribute value | ||
if (isBind) { | ||
var unwatch = scope.$watch(originalValue, function (value) { | ||
if (value !== undefined && value !== null) { | ||
value = filterType === 'file' ? | ||
// if we are binding to the attribute value | ||
if (isBind) { | ||
var unwatch = scope.$watch(originalValue, function (value) { | ||
if (value !== undefined && value !== null) { | ||
value = filterType === 'file' ? | ||
config.staticFileRoot + value : | ||
i18n.translate(value); | ||
i18n.translate(value); | ||
attrName === 'text' ? | ||
element.text(value) : | ||
attrName === 'class' ? | ||
attrs.$addClass(value) : | ||
attrs.$set(attrName, value, scope); | ||
attrName === 'text' ? | ||
element.text(value) : | ||
attrName === 'class' ? | ||
attrs.$addClass(value) : | ||
attrs.$set(attrName, value, scope); | ||
// if bind once, we are unwatch after the first time | ||
if (isBindOnce && unwatch) { unwatch(); } | ||
} | ||
}); | ||
} | ||
// if bind once, we are unwatch after the first time | ||
if (isBindOnce && unwatch) { unwatch(); } | ||
} | ||
}); | ||
} | ||
// else we are not binding, but we want to do some filtering | ||
else if (!isBind && filterType !== null) { | ||
// else we are not binding, but we want to do some filtering | ||
else if (!isBind && filterType !== null) { | ||
// if the value contains {{ it means there is interpolation | ||
if (originalValue.indexOf('{{') >= 0) { | ||
var unobserve = attrs.$observe(directiveName, function (value) { | ||
value = filterType === 'file' ? | ||
// if the value contains {{ it means there is interpolation | ||
if (originalValue.indexOf('{{') >= 0) { | ||
var unobserve = attrs.$observe(directiveName, function (value) { | ||
value = filterType === 'file' ? | ||
config.staticFileRoot + value : | ||
i18n.translate(value, scope); | ||
i18n.translate(value, scope); | ||
attrName === 'text' ? | ||
element.text(value) : | ||
attrs.$set(attrName, value, scope); | ||
attrName === 'text' ? | ||
element.text(value) : | ||
attrs.$set(attrName, value, scope); | ||
if (isBindOnce && unobserve) { unobserve(); } | ||
}); | ||
} | ||
// else we are very simply setting the value | ||
else { | ||
var targetValue = filterType === 'file' ? | ||
if (isBindOnce && unobserve) { unobserve(); } | ||
}); | ||
} | ||
// else we are very simply setting the value | ||
else { | ||
var targetValue = filterType === 'file' ? | ||
config.staticFileRoot + originalValue : | ||
i18n.translate(originalValue); | ||
i18n.translate(originalValue); | ||
attrName === 'text' ? | ||
element.text(targetValue) : | ||
attrs.$set(attrName, targetValue, scope); | ||
attrName === 'text' ? | ||
element.text(targetValue) : | ||
attrs.$set(attrName, targetValue, scope); | ||
} | ||
} | ||
@@ -877,12 +880,14 @@ } | ||
* if no defaults value, then error thrown. | ||
* This matches jng.utils.setOptions() | ||
* This matches jng.utils.applyPresets() | ||
* | ||
* @param scope | ||
* @param defaults | ||
* @param options | ||
* @param presets | ||
*/ | ||
function setOptions(scope, defaults, options) { | ||
if (!scope || !scope.optgrp || !options) { return; } | ||
function applyPresets(scope, defaults, presets) { | ||
if (!scope || !presets) { return; } | ||
var opts = options[scope.optgrp] || options[scope.type + '.' + scope.optgrp]; | ||
// presets come from either scope (i.e. passed in directly) or get from the ui part presets | ||
var opts = scope.presets || presets[scope.preset] || | ||
(scope.preset && presets[scope.type + '.' + scope.preset]) || presets[scope.type]; | ||
if (!opts) { return; } | ||
@@ -893,3 +898,3 @@ | ||
if (!defaults || defaults[name] === undefined) { | ||
throw new Error('No defaults value for ' + name + ' but in options.' + scope.optgrp); | ||
throw new Error('No defaults value for ' + name + ' but in options.' + scope.preset); | ||
} | ||
@@ -1226,3 +1231,3 @@ else { | ||
setDefaults: setDefaults, | ||
setOptions: setOptions, | ||
applyPresets: applyPresets, | ||
generateRerender: generateRerender, | ||
@@ -1229,0 +1234,0 @@ generateRemodel: generateRemodel, |
@@ -1,1 +0,1 @@ | ||
angular.module("pancakesAngular",[]),"#_=_"===window.location.hash&&(history.replaceState?history.replaceState(null,null,window.location.href.split("#")[0]):window.location.hash=""),angular.module("pancakesAngular").factory("activeUser",function(){return{}}),angular.module("pancakesAngular").factory("ajax",["$q","$http","eventBus","config",function(n,e,t,r){function a(a,o,i,u){var l,c,s=n.defer(),f=[];a=r.apiBase+a,i=i||{};var d=i.data;delete i.data,a.indexOf("{_id}")>=0?i._id?(a=a.replace("{_id}",i._id),delete i._id):d&&d._id&&(a=a.replace("{_id}",d._id)):"GET"===o&&i._id&&(a+="/"+i._id,delete i._id);var g=i.showErr!==!1;delete i.showErr,i.lang=i.lang||r.lang;for(l in i)i.hasOwnProperty(l)&&i[l]&&(c=i[l],c=angular.isObject(c)?JSON.stringify(c):c,f.push(encodeURIComponent(l)+"="+encodeURIComponent(c)));f.length&&(a+="?"+f.join("&"));var p={method:o,url:a,withCredentials:!0,cache:!1};return d&&(p.data=d),t.emit(u+"."+o.toLowerCase()+".start"),e(p).success(function(n){s.resolve(n)}).error(function(n){n?(g&&t.emit("error.api",n),s.reject(n)):s.resolve()}).finally(function(){t.emit(u+"."+o.toLowerCase()+".end")}),s.promise}return{send:a}}]),angular.module("pancakesAngular").factory("chainPromises",["$q",function(n){return function(e,t){return e&&e.length?e.reduce(n.when,n.when(t)):n.when(t)}}]),angular.module("pancakesAngular").factory("eventBus",["$document","$rootScope",function(n,e){var t=e.$new(!0);return t.on=t.$on,t.watch=t.$watch,t.emit=function(){e.$broadcast.apply(e,arguments)},t.bindToDocument=function(e,t){n.bind(e,t)},t}]),angular.module("pancakesAngular").factory("config",function(){return{staticFileRoot:"/"}}),function(){function n(n,e,t,r,o){a.directive(n,["i18n","config",function(a,i){return function(u,l,c){var s=c[n];if(r)var f=u.$watch(s,function(n){void 0!==n&&null!==n&&(n="file"===t?i.staticFileRoot+n:a.translate(n),"text"===e?l.text(n):"class"===e?c.$addClass(n):c.$set(e,n,u),o&&f&&f())});else if(!r&&null!==t)if(s.indexOf("{{")>=0)var d=c.$observe(n,function(n){n="file"===t?i.staticFileRoot+n:a.translate(n,u),"text"===e?l.text(n):c.$set(e,n,u),o&&d&&d()});else{var g="file"===t?i.staticFileRoot+s:a.translate(s);"text"===e?l.text(g):c.$set(e,g,u)}}}])}var e,t,r={href:"file",src:"file",title:"i18n",placeholder:"i18n",popover:"i18n",value:"i18n",alt:"i18n",text:"i18n",id:null,type:null,"class":null},a=angular.module("pancakesAngular");for(var o in r)r.hasOwnProperty(o)&&(e=o.substring(0,1).toUpperCase()+o.substring(1),n("b"+e,o,null,!0,!1),n("bo"+e,o,null,!0,!0),t=r[o],t&&(n("f"+e,o,t,!1,!1),n("fo"+e,o,t,!1,!0),n("bf"+e,o,t,!0,!1),n("bfo"+e,o,t,!0,!0)))}(),angular.module("pancakesAngular").factory("i18n",function(){return{translate:function(n){return n}}}),angular.module("pancakesAngular").factory("initialModel",function(){return{}}),angular.module("pancakesAngular").factory("pageSettings",["$window","$rootElement",function(n,e){function t(t,r){n.document.title=t;var a=angular.element(e.find("meta[name=description]")[0]);a.attr("content",r)}function r(n){var t="gh-"+n.replace(".","-"),r=e.find(".maincontent");r&&r.length&&(r=angular.element(r[0]),r.attr("id",t))}return{updateHead:t,updatePageStyle:r}}]),angular.module("pancakesAngular").factory("serviceHelper",["ajax",function(n){function e(e){return function(t){return n.send(e.url,e.httpMethod,t,e.resourceName)}}function t(n){var t={};for(var r in n)n.hasOwnProperty(r)&&(t[r]=e(n[r]));return t}function r(n){var e=function(n){this.data=n};return e.prototype.save=function(){return this.data&&this.data._id?n.update({data:this.data}):n.create({data:this.data})},angular.extend(e,n),e}return{genServiceMethod:e,genService:t,genModel:r}}]),angular.module("pancakesAngular").provider("stateLoader",function(){function n(n){for(var e=n.split("."),t="",r=0;r<e.length;r++)t+=e[r].substring(0,1).toUpperCase()+e[r].substring(1);return t}this.loadStates=function(e,t,r){var a={};angular.forEach(t,function(t){angular.forEach(t.urls,function(o,i){var u=r[t.name]||function(){return{}},l=(t.name+(0===i?"":"--"+i)).replace(/\./g,"-"),c={url:o,resolve:{initialModel:u,loadedUser:["activeUser",function(n){return n.init()}]},onEnter:["$rootScope",function(n){n.stateData=t.data||{},n.pageLoadTimestamp=(new Date).getTime()}],views:{"":{controller:n(t.name+"Ctrl"),templateUrl:"templates/"+t.name}}};a[l]&&(l+=(new Date).getTime()),a[l]=!0,e.state(l,c)})})},this.$get=function(){return{getPascalCase:n}}}),angular.module("pancakesAngular").factory("tplHelper",["$q","$injector","config","pageSettings","eventBus",function(n,e,t,r,a){function o(n,e){if(e){n.defaults=e;for(var t in e)e.hasOwnProperty(t)&&void 0===n[t]&&(n[t]=e[t])}}function i(n,e,t){if(n&&n.optgrp&&t){var r=t[n.optgrp]||t[n.type+"."+n.optgrp];if(r)for(var a in r)if(r.hasOwnProperty(a)){if(!e||void 0===e[a])throw new Error("No defaults value for "+a+" but in options."+n.optgrp);n[a]=r[a]}}}function u(n,e){e&&(n.rerenderComponent=function(){e.go(e.current,{},{reload:!0})})}function l(t,r,a,o,i){o&&(i=i||{},t.remodel=function(){var a={currentScope:t,defaults:t.defaults};try{angular.isFunction(o)||angular.isArray(o)&&angular.isFunction(o[o.length-1])?n.when(e.invoke(o,null,a)).then(function(n){angular.forEach(n,function(n,e){if(i[e])throw new Error(r+" model() should not return "+e+" from the parent scope");t[e]=n})}):angular.forEach(o,function(o,u){if("end"!==u){if(i[u])throw new Error(r+" model() should not return "+u+" from the parent scope");angular.isFunction(o)||angular.isArray(o)&&angular.isFunction(o[o.length-1])?n.when(e.invoke(o,null,a)).then(function(n){t[u]=n}):t[u]=o}})}catch(u){throw console.log(r+" has err "),u}},a&&t.remodel())}function c(n,t){for(var r in t)t.hasOwnProperty(r)&&t[r]&&(n[r]=e.invoke(t[r]))}function s(n,t){t&&t.length&&(t.push(function(){var e,r;for(e=0;e<arguments.length;e++)r=arguments[e],n[t[e]]=r}),e.invoke(t))}function f(n){var e=!0;return function(){e?e=!1:n()}}function d(n,e,t){var r,a,o,i;if(e&&t)for(r=0;r<e.length;r++)i=f(t),a=e[r],o=a.charAt(0),"^"===o?n.$watchCollection(a.substring(1),i):"*"===o?n.$watch(a.substring(1),i,!0):n.$watch(a,i)}function g(e){return function(){var t=e.remodel||function(){return!0};n.when(t(e)).then(function(){e.rerenderComponent()})}}function p(n,e){return d(n,e,n.remodel)}function h(n,e){return d(n,e,g(n))}function v(n,e,t){var r,o,i=[];if(e&&t){for(r=0;r<e.length;r++)o=e[r],i.push(a.on(o,t));n.$on("$destroy",function(){for(var n=0;n<i.length;n++)i[n]()})}}function m(n,e){return v(n,e,n.remodel)}function w(n,e){return v(n,e,g(n))}function y(n,e,t){if(angular.extend(n,e),n.pageHead&&n.pageHead.title){var a=n.pageHead.title;r.updateHead(a,n.pageHead.description||a),r.updatePageStyle(t)}}function $(n,t){var r=[];for(var o in t)t.hasOwnProperty(o)&&t[o]&&r.push(a.on(o,e.invoke(t[o])));n.$on("$destroy",function(){for(var n=0;n<r.length;n++)r[n]()})}function k(n,t,r){if(r)for(var a in r)if(r.hasOwnProperty(a)&&r[a]&&(n[a]=e.invoke(r[a]),!angular.isFunction(n[a])))throw new Error(t+" has uiEventHandler "+a+" that does not return a function")}return{setDefaults:o,setOptions:i,generateRerender:u,generateRemodel:l,addValidations:c,attachToScope:s,generateRerenderCallback:g,rerenderOnScopeChange:h,rerenderOnEvent:w,remodelOnScopeChange:p,remodelOnEvent:m,generateScopeChangeHandler:f,doOnScopeChange:d,doOnEvent:v,addInitModel:y,registerListeners:$,addEventHandlers:k}}]); | ||
angular.module("pancakesAngular",[]),"#_=_"===window.location.hash&&(history.replaceState?history.replaceState(null,null,window.location.href.split("#")[0]):window.location.hash=""),angular.module("pancakesAngular").factory("activeUser",function(){return{}}),angular.module("pancakesAngular").factory("ajax",["$q","$http","eventBus","config",function(n,e,t,r){function a(a,o,i,u){var l,c,s=n.defer(),f=[];a=r.apiBase+a,i=i||{};var d=i.data;delete i.data,a.indexOf("{_id}")>=0?i._id?(a=a.replace("{_id}",i._id),delete i._id):d&&d._id&&(a=a.replace("{_id}",d._id)):"GET"===o&&i._id&&(a+="/"+i._id,delete i._id);var g=i.showErr!==!1;delete i.showErr,i.lang=i.lang||r.lang;for(l in i)i.hasOwnProperty(l)&&i[l]&&(c=i[l],c=angular.isObject(c)?JSON.stringify(c):c,f.push(encodeURIComponent(l)+"="+encodeURIComponent(c)));f.length&&(a+="?"+f.join("&"));var p={method:o,url:a,withCredentials:!0,cache:!1};return d&&(p.data=d),t.emit(u+"."+o.toLowerCase()+".start"),e(p).success(function(n){s.resolve(n)}).error(function(n){n?(g&&t.emit("error.api",n),s.reject(n)):s.resolve()}).finally(function(){t.emit(u+"."+o.toLowerCase()+".end")}),s.promise}return{send:a}}]),angular.module("pancakesAngular").factory("chainPromises",["$q",function(n){return function(e,t){return e&&e.length?e.reduce(n.when,n.when(t)):n.when(t)}}]),angular.module("pancakesAngular").factory("eventBus",["$document","$rootScope",function(n,e){var t=e.$new(!0);return t.on=t.$on,t.watch=t.$watch,t.emit=function(){e.$broadcast.apply(e,arguments)},t.bindToDocument=function(e,t){n.bind(e,t)},t}]),angular.module("pancakesAngular").factory("config",function(){return{staticFileRoot:"/"}}),function(){function n(n,e,t,r,o){a.directive(n,["i18n","config",function(a,i){return{priority:101,link:function(u,l,c){var s=c[n];if(r)var f=u.$watch(s,function(n){void 0!==n&&null!==n&&(n="file"===t?i.staticFileRoot+n:a.translate(n),"text"===e?l.text(n):"class"===e?c.$addClass(n):c.$set(e,n,u),o&&f&&f())});else if(!r&&null!==t)if(s.indexOf("{{")>=0)var d=c.$observe(n,function(n){n="file"===t?i.staticFileRoot+n:a.translate(n,u),"text"===e?l.text(n):c.$set(e,n,u),o&&d&&d()});else{var g="file"===t?i.staticFileRoot+s:a.translate(s);"text"===e?l.text(g):c.$set(e,g,u)}}}}])}var e,t,r={href:"file",src:"file",title:"i18n",placeholder:"i18n",popover:"i18n",value:"i18n",alt:"i18n",text:"i18n",id:null,type:null,"class":null},a=angular.module("pancakesAngular");for(var o in r)r.hasOwnProperty(o)&&(e=o.substring(0,1).toUpperCase()+o.substring(1),n("b"+e,o,null,!0,!1),n("bo"+e,o,null,!0,!0),t=r[o],t&&(n("f"+e,o,t,!1,!1),n("fo"+e,o,t,!1,!0),n("bf"+e,o,t,!0,!1),n("bfo"+e,o,t,!0,!0)))}(),angular.module("pancakesAngular").factory("i18n",function(){return{translate:function(n){return n}}}),angular.module("pancakesAngular").factory("initialModel",function(){return{}}),angular.module("pancakesAngular").factory("pageSettings",["$window","$rootElement",function(n,e){function t(t,r){n.document.title=t;var a=angular.element(e.find("meta[name=description]")[0]);a.attr("content",r)}function r(n){var t="gh-"+n.replace(".","-"),r=e.find(".maincontent");r&&r.length&&(r=angular.element(r[0]),r.attr("id",t))}return{updateHead:t,updatePageStyle:r}}]),angular.module("pancakesAngular").factory("serviceHelper",["ajax",function(n){function e(e){return function(t){return n.send(e.url,e.httpMethod,t,e.resourceName)}}function t(n){var t={};for(var r in n)n.hasOwnProperty(r)&&(t[r]=e(n[r]));return t}function r(n){var e=function(n){this.data=n};return e.prototype.save=function(){return this.data&&this.data._id?n.update({data:this.data}):n.create({data:this.data})},angular.extend(e,n),e}return{genServiceMethod:e,genService:t,genModel:r}}]),angular.module("pancakesAngular").provider("stateLoader",function(){function n(n){for(var e=n.split("."),t="",r=0;r<e.length;r++)t+=e[r].substring(0,1).toUpperCase()+e[r].substring(1);return t}this.loadStates=function(e,t,r){var a={};angular.forEach(t,function(t){angular.forEach(t.urls,function(o,i){var u=r[t.name]||function(){return{}},l=(t.name+(0===i?"":"--"+i)).replace(/\./g,"-"),c={url:o,resolve:{initialModel:u,loadedUser:["activeUser",function(n){return n.init()}]},onEnter:["$rootScope",function(n){n.stateData=t.data||{},n.pageLoadTimestamp=(new Date).getTime()}],views:{"":{controller:n(t.name+"Ctrl"),templateUrl:"templates/"+t.name}}};a[l]&&(l+=(new Date).getTime()),a[l]=!0,e.state(l,c)})})},this.$get=function(){return{getPascalCase:n}}}),angular.module("pancakesAngular").factory("tplHelper",["$q","$injector","config","pageSettings","eventBus",function(n,e,t,r,a){function o(n,e){if(e){n.defaults=e;for(var t in e)e.hasOwnProperty(t)&&void 0===n[t]&&(n[t]=e[t])}}function i(n,e,t){if(n&&t){var r=n.presets||t[n.preset]||n.preset&&t[n.type+"."+n.preset]||t[n.type];if(r)for(var a in r)if(r.hasOwnProperty(a)){if(!e||void 0===e[a])throw new Error("No defaults value for "+a+" but in options."+n.preset);n[a]=r[a]}}}function u(n,e){e&&(n.rerenderComponent=function(){e.go(e.current,{},{reload:!0})})}function l(t,r,a,o,i){o&&(i=i||{},t.remodel=function(){var a={currentScope:t,defaults:t.defaults};try{angular.isFunction(o)||angular.isArray(o)&&angular.isFunction(o[o.length-1])?n.when(e.invoke(o,null,a)).then(function(n){angular.forEach(n,function(n,e){if(i[e])throw new Error(r+" model() should not return "+e+" from the parent scope");t[e]=n})}):angular.forEach(o,function(o,u){if("end"!==u){if(i[u])throw new Error(r+" model() should not return "+u+" from the parent scope");angular.isFunction(o)||angular.isArray(o)&&angular.isFunction(o[o.length-1])?n.when(e.invoke(o,null,a)).then(function(n){t[u]=n}):t[u]=o}})}catch(u){throw console.log(r+" has err "),u}},a&&t.remodel())}function c(n,t){for(var r in t)t.hasOwnProperty(r)&&t[r]&&(n[r]=e.invoke(t[r]))}function s(n,t){t&&t.length&&(t.push(function(){var e,r;for(e=0;e<arguments.length;e++)r=arguments[e],n[t[e]]=r}),e.invoke(t))}function f(n){var e=!0;return function(){e?e=!1:n()}}function d(n,e,t){var r,a,o,i;if(e&&t)for(r=0;r<e.length;r++)i=f(t),a=e[r],o=a.charAt(0),"^"===o?n.$watchCollection(a.substring(1),i):"*"===o?n.$watch(a.substring(1),i,!0):n.$watch(a,i)}function g(e){return function(){var t=e.remodel||function(){return!0};n.when(t(e)).then(function(){e.rerenderComponent()})}}function p(n,e){return d(n,e,n.remodel)}function h(n,e){return d(n,e,g(n))}function v(n,e,t){var r,o,i=[];if(e&&t){for(r=0;r<e.length;r++)o=e[r],i.push(a.on(o,t));n.$on("$destroy",function(){for(var n=0;n<i.length;n++)i[n]()})}}function m(n,e){return v(n,e,n.remodel)}function w(n,e){return v(n,e,g(n))}function y(n,e,t){if(angular.extend(n,e),n.pageHead&&n.pageHead.title){var a=n.pageHead.title;r.updateHead(a,n.pageHead.description||a),r.updatePageStyle(t)}}function $(n,t){var r=[];for(var o in t)t.hasOwnProperty(o)&&t[o]&&r.push(a.on(o,e.invoke(t[o])));n.$on("$destroy",function(){for(var n=0;n<r.length;n++)r[n]()})}function k(n,t,r){if(r)for(var a in r)if(r.hasOwnProperty(a)&&r[a]&&(n[a]=e.invoke(r[a]),!angular.isFunction(n[a])))throw new Error(t+" has uiEventHandler "+a+" that does not return a function")}return{setDefaults:o,applyPresets:i,generateRerender:u,generateRemodel:l,addValidations:c,attachToScope:s,generateRerenderCallback:g,rerenderOnScopeChange:h,rerenderOnEvent:w,remodelOnScopeChange:p,remodelOnEvent:m,generateScopeChangeHandler:f,doOnScopeChange:d,doOnEvent:v,addInitModel:y,registerListeners:$,addEventHandlers:k}}]); |
@@ -185,4 +185,4 @@ /** | ||
// set the options if they exist | ||
me.setOptions(model, partial.defaults, partial.options); | ||
// set the presets if they exist | ||
me.applyPresets(model, partial.defaults, partial.presets); | ||
@@ -189,0 +189,0 @@ // if model is injection function, just use that |
@@ -51,3 +51,3 @@ /** | ||
this.setDefaults(model, page.defaults, null); | ||
this.setOptions(model, page.defaults, page.options); | ||
this.applyPresets(model, page.defaults, page.presets); | ||
this.attachToScope(model, page.attachToScope); | ||
@@ -54,0 +54,0 @@ this.addFiltersToModel(model, routeInfo.appName); |
@@ -36,12 +36,13 @@ /** | ||
* if no defaults value, then error thrown. | ||
* This matches tpl.helper.setOptions() | ||
* This matches tpl.helper.applyPresets() | ||
* | ||
* @param model | ||
* @param defaults | ||
* @param options | ||
* @param presets | ||
*/ | ||
function setOptions(model, defaults, options) { | ||
if (!model || !model.optgrp || !options) { return; } | ||
function applyPresets(model, defaults, presets) { | ||
if (!model || !presets) { return; } | ||
var opts = options[model.optgrp] || options[model.type + '.' + model.optgrp]; | ||
var opts = model.presets || presets[model.preset] || | ||
(model.preset && presets[model.type + '.' + model.preset]) || presets[model.type]; | ||
if (!opts) { return; } | ||
@@ -52,3 +53,3 @@ | ||
if (!defaults || defaults[name] === undefined) { | ||
throw new Error('No defaults value for ' + name + ' but in options.' + model.optgrp); | ||
throw new Error('No defaults value for ' + name + ' but in presets.' + model.preset); | ||
} | ||
@@ -174,3 +175,3 @@ else { | ||
setDefaults: setDefaults, | ||
setOptions: setOptions, | ||
applyPresets: applyPresets, | ||
attachToScope: attachToScope, | ||
@@ -177,0 +178,0 @@ getAppFileNames: getAppFileNames, |
@@ -31,51 +31,54 @@ /** | ||
app.directive(directiveName, ['i18n', 'config', function (i18n, config) { | ||
return function (scope, element, attrs) { | ||
var originalValue = attrs[directiveName]; | ||
return { | ||
priority: 101, | ||
link: function linkFn(scope, element, attrs) { | ||
var originalValue = attrs[directiveName]; | ||
// if we are binding to the attribute value | ||
if (isBind) { | ||
var unwatch = scope.$watch(originalValue, function (value) { | ||
if (value !== undefined && value !== null) { | ||
value = filterType === 'file' ? | ||
// if we are binding to the attribute value | ||
if (isBind) { | ||
var unwatch = scope.$watch(originalValue, function (value) { | ||
if (value !== undefined && value !== null) { | ||
value = filterType === 'file' ? | ||
config.staticFileRoot + value : | ||
i18n.translate(value); | ||
i18n.translate(value); | ||
attrName === 'text' ? | ||
element.text(value) : | ||
attrName === 'class' ? | ||
attrs.$addClass(value) : | ||
attrs.$set(attrName, value, scope); | ||
attrName === 'text' ? | ||
element.text(value) : | ||
attrName === 'class' ? | ||
attrs.$addClass(value) : | ||
attrs.$set(attrName, value, scope); | ||
// if bind once, we are unwatch after the first time | ||
if (isBindOnce && unwatch) { unwatch(); } | ||
} | ||
}); | ||
} | ||
// if bind once, we are unwatch after the first time | ||
if (isBindOnce && unwatch) { unwatch(); } | ||
} | ||
}); | ||
} | ||
// else we are not binding, but we want to do some filtering | ||
else if (!isBind && filterType !== null) { | ||
// else we are not binding, but we want to do some filtering | ||
else if (!isBind && filterType !== null) { | ||
// if the value contains {{ it means there is interpolation | ||
if (originalValue.indexOf('{{') >= 0) { | ||
var unobserve = attrs.$observe(directiveName, function (value) { | ||
value = filterType === 'file' ? | ||
// if the value contains {{ it means there is interpolation | ||
if (originalValue.indexOf('{{') >= 0) { | ||
var unobserve = attrs.$observe(directiveName, function (value) { | ||
value = filterType === 'file' ? | ||
config.staticFileRoot + value : | ||
i18n.translate(value, scope); | ||
i18n.translate(value, scope); | ||
attrName === 'text' ? | ||
element.text(value) : | ||
attrs.$set(attrName, value, scope); | ||
attrName === 'text' ? | ||
element.text(value) : | ||
attrs.$set(attrName, value, scope); | ||
if (isBindOnce && unobserve) { unobserve(); } | ||
}); | ||
} | ||
// else we are very simply setting the value | ||
else { | ||
var targetValue = filterType === 'file' ? | ||
if (isBindOnce && unobserve) { unobserve(); } | ||
}); | ||
} | ||
// else we are very simply setting the value | ||
else { | ||
var targetValue = filterType === 'file' ? | ||
config.staticFileRoot + originalValue : | ||
i18n.translate(originalValue); | ||
i18n.translate(originalValue); | ||
attrName === 'text' ? | ||
element.text(targetValue) : | ||
attrs.$set(attrName, targetValue, scope); | ||
attrName === 'text' ? | ||
element.text(targetValue) : | ||
attrs.$set(attrName, targetValue, scope); | ||
} | ||
} | ||
@@ -82,0 +85,0 @@ } |
@@ -33,12 +33,14 @@ /** | ||
* if no defaults value, then error thrown. | ||
* This matches jng.utils.setOptions() | ||
* This matches jng.utils.applyPresets() | ||
* | ||
* @param scope | ||
* @param defaults | ||
* @param options | ||
* @param presets | ||
*/ | ||
function setOptions(scope, defaults, options) { | ||
if (!scope || !scope.optgrp || !options) { return; } | ||
function applyPresets(scope, defaults, presets) { | ||
if (!scope || !presets) { return; } | ||
var opts = options[scope.optgrp] || options[scope.type + '.' + scope.optgrp]; | ||
// presets come from either scope (i.e. passed in directly) or get from the ui part presets | ||
var opts = scope.presets || presets[scope.preset] || | ||
(scope.preset && presets[scope.type + '.' + scope.preset]) || presets[scope.type]; | ||
if (!opts) { return; } | ||
@@ -49,3 +51,3 @@ | ||
if (!defaults || defaults[name] === undefined) { | ||
throw new Error('No defaults value for ' + name + ' but in options.' + scope.optgrp); | ||
throw new Error('No defaults value for ' + name + ' but in options.' + scope.preset); | ||
} | ||
@@ -382,3 +384,3 @@ else { | ||
setDefaults: setDefaults, | ||
setOptions: setOptions, | ||
applyPresets: applyPresets, | ||
generateRerender: generateRerender, | ||
@@ -385,0 +387,0 @@ generateRemodel: generateRemodel, |
@@ -121,3 +121,3 @@ /** | ||
var defaults = uipart.defaults ? JSON.stringify(uipart.defaults) : 'null'; | ||
var uiopts = uipart.options ? JSON.stringify(uipart.options) : null; | ||
var presets = uipart.presets ? JSON.stringify(uipart.presets) : null; | ||
var attachToScope = uipart.attachToScope ? JSON.stringify(uipart.attachToScope) : null; | ||
@@ -138,3 +138,3 @@ var paramInfo = this.getFilteredParamInfo(uipart.controller, options); | ||
defaults: defaults, | ||
options: uiopts, | ||
presets: presets, | ||
attachToScope: attachToScope, | ||
@@ -141,0 +141,0 @@ rerenderExists: useRerenderOnEvent || useRemodelOnWatch, |
{ | ||
"name": "pancakes-angular", | ||
"version": "0.1.27", | ||
"version": "0.1.28", | ||
"description": "Pancakes plugin for Angular", | ||
@@ -5,0 +5,0 @@ "main": "lib/pancakes.angular.plugin.js", |
@@ -91,3 +91,4 @@ /** | ||
defaults: 'null', | ||
attachToScope: 'null', | ||
presets: null, | ||
attachToScope: null, | ||
rerenderExists: undefined, | ||
@@ -94,0 +95,0 @@ remodelExists: undefined, |
Sorry, the diff of this file is not supported yet
191855
4517