generator-beez
Version:
A beez project generator for Yeoman
24 lines (21 loc) • 38.2 kB
JavaScript
/**
* @name base.js<beez-mvcr>
* @author Kei Funagayama <funagayama_kei@cyberagent.co.jp>
* copyright (c) Cyberagent Inc.
* @overview base class of managed object
*/
/* JSONPath 0.8.0 - XPath for JSON
*
* Copyright (c) 2007 Stefan Goessner (goessner.net)
* Licensed under the MIT (MIT-LICENSE.txt) licence.
*
* @license https://github.com/s3u/JSONPath
*/
/**
* @name base.js<beez-mvcr>
* @author Kazuma MISHIMAGI <mishimagi_kazuma@cyberagent.co.jp">
* copyright (c) Cyberagent Inc.
* @overview base class of managed object
*/
!function(global){define("beez-mvcr/jsonpath",["require","exports","module","beez.core"],function(require,exports,module){var beez=require("beez.core"),_=beez.vendor._,cache={},jsonPath=function jsonPath(obj,expr,arg,testManaged){var P={resultType:arg&&arg.resultType||"VALUE",flatten:arg&&arg.flatten||!1,wrap:arg&&arg.hasOwnProperty("wrap")?arg.wrap:!0,normalize:function(e){if(cache[e])return cache[e];var t=[],r=e.replace(/[\['](\??\(.*?\))[\]']/g,function(e,r){return"[#"+(t.push(r)-1)+"]"}).replace(/'?\.'?|\['?/g,";").replace(/;;;|;;/g,";..;").replace(/;$|'?\]|'$/g,"").replace(/#([0-9]+)/g,function(e,r){return t[r]});return cache[e]=r,r},asPath:function(e){for(var t=e.split(";"),r="$",n=1,i=t.length;i>n;n++)r+=/^[0-9*]+$/.test(t[n])?"["+t[n]+"]":"['"+t[n]+"']";return r},store:function(e,t){return e&&("PATH"===P.resultType?P.result[P.result.length]=P.asPath(e):_.isArray(t)&&P.flatten?(P.result||(P.result=[]),_.isArray(P.result)||(P.result=[P.result]),P.result=P.result.concat(t)):P.result?(_.isArray(P.result)||(P.result=[P.result]),_.isArray(t)&&P.flatten?P.result=P.result.concat(t):P.result[P.result.length]=t):P.result=t),!!e},trace:function(e,t,r){if(e){var n=e.split(";"),i=n.shift();if(n=n.join(";"),t&&t.hasOwnProperty(i))P.trace(n,t[i],r+";"+i);else if("*"===i)P.walk(i,n,t,r,function(e,t,r,n,i){P.trace(e+";"+r,n,i)});else if(".."===i)P.trace(n,t,r),P.walk(i,n,t,r,function(e,t,r,n,i){"object"==typeof n[e]&&P.trace("..;"+r,n[e],i+";"+e)});else if(/,/.test(i))for(var o=i.split(/'?,'?/),s=0,a=o.length;a>s;s++)P.trace(o[s]+";"+n,t,r);else/^\(.*?\)$/.test(i)?P.trace(P.evaluate(i,t,r.substr(r.lastIndexOf(";")+1))+";"+n,t,r):/^\?\(.*?\)$/.test(i)?P.walk(i,n,t,r,function(e,t,r,n,i){P.evaluate(t.replace(/^\?\((.*?)\)$/,"$1"),n[e],e)&&P.trace(e+";"+r,n,i)}):/^(-?[0-9]*):(-?[0-9]*):?([0-9]*)$/.test(i)&&P.slice(i,n,t,r)}else t&&(_.isArray(t)||testManaged(t))&&P.store(r,t)},walk:function(e,t,r,n,i){if(r instanceof Array)for(var o=0,s=r.length;s>o;o++)o in r&&i(o,e,t,r,n);else if("object"==typeof r&&testManaged(r))for(var a in r)r.hasOwnProperty(a)&&i(a,e,t,r,n)},slice:function(e,t,r,n){if(r instanceof Array){var i=r.length,o=0,s=i,a=1;e.replace(/^(-?[0-9]*):(-?[0-9]*):?(-?[0-9]*)$/g,function(e,t,r,n){o=parseInt(t||o,10),s=parseInt(r||s,10),a=parseInt(n||a,10)}),o=0>o?Math.max(0,o+i):Math.min(i,o),s=0>s?Math.max(0,s+i):Math.min(i,s);for(var c=o;s>c;c+=a)P.trace(c+";"+t,r,n)}},evaluate:function(x,_v,_vname){try{return $&&_v&&eval(x)}catch(e){throw new SyntaxError("jsonPath: "+e.message+": "+x.replace(/\^/g,"_a"))}}};P.result=P.wrap===!0?[]:void 0;var $=obj;return expr&&obj&&("VALUE"===P.resultType||"PATH"===P.resultType)?(P.trace(P.normalize(expr).replace(/^\$;/,""),obj,"$"),!_.isArray(P.result)&&P.wrap&&(P.result=[P.result]),P.result?P.result:!1):void 0};return jsonPath})}(this),function(){define("beez-mvcr/base",["require","exports","module","beez.core","beez-mvcr/jsonpath"],function(e){var t=e("beez.core"),r=t.vendor._,n=e("beez-mvcr/jsonpath"),i=t.getLogger("beez.mvcr.base"),o=t.extend("beez.manager.ManagerBase",function(){},{constructor:function(e){this.objs={},this.objs[e]="$",this._idxProp=e||"",this.initialize.apply(this,arguments)},initialize:function(){},getIdx:function(e){return e[this._idxProp]},add:function(e,n){var i=this.get(e);if(!i)throw new t.Error("no parent exists. path: "+e);if(r.isArray(i))throw new t.Error("parent is Array. Specify one by using `[number]` selector. parent: "+i);if(r.isArray(n))r.each(n,function(t){t.prefix=e;var r=this.getIdx(t);i[r]||(i[r]=[]),i[r].push(t)},this);else{n.prefix=e;var o=this.getIdx(n);if(i[o])throw new t.Error("Obj: adding object to same parent with same index. Add obj as Array to add several objs into same index. idx: "+this.getIdx(n));i[o]=n}return this},remove:function(e){var t,n=this.get(e),i=[];n&&(r.isArray(n)||(n=[n]),r.each(n,function(e){var t=this.getChildrenAll(e);i=i.concat(t)},this),t=i.concat(n),r.each(t,function(e){this.deleteFromParent(e)},this),r.each(t,function(e){e.dispose&&e.dispose()}))},isAddable:function(e){return!!this.getIdx(e)},get:function(e){if(void 0===e||"string"!=typeof e)return void 0;if(/^\/$/.test(e))return this.objs;var t=this;e="$"+e.replace(/\//g,".");var r=n(this.objs,e,{wrap:!1},function(e){return t.isAddable(e)});return r?r:void 0},getParent:function(e){return r.isArray(e)?this.get(e[0].prefix):this.get(e.prefix)},deleteFromParent:function(e){if(e){var t=this.getParent(e);r.isArray(e)?delete t[this.getIdx(e[0])]:delete t[this.getIdx(e)]}},getChildren:function(e){var t=[],n=this,i=function o(e){r.each(e,function(e){e&&(r.isArray(e)?o(e):n.getIdx(e)&&t.push(e))})};return i(e),t},getChildrenAll:function(e){var t=[],n=this,o=function s(e){var o=e;r.isArray(e)||(o=r.values(e)),r.each(o,function(o){if(o)if(r.isArray(o))s(o);else if(n.getIdx(o)){if(!o.prefix||!o.manager)return i.warn("Manager ignore the Object haven't been manaegd.",o),void 0;if("$"!==e[n._idxProp]&&!r.isArray(e)&&o.getParent()[n._idxProp]!==e[n._idxProp])return i.warn("Manager ignore the Object haven't been manaegd.","Path that is managed:",n.pathOf(o),"Path to the specified:",n.pathOf(e)),void 0;s(o),t.push(o)}})};return o(e),t},pathOf:function(e){var n="";if(r.isArray(e)){if(r.isEmpty(e))throw new t.Error("pathOf: obj is empty array.");e=e[0]}if(n=e.prefix,!n)throw new t.Error("pathOf: object.prefix does not exist.");return n+(/^\/$/.test(n)?"":"/")+this.getIdx(e)},trace:function(){var e={},t=this.getChildrenAll(this.objs||{}),n=this;return r.each(t,function(t){if(t){var i;i="/"===t.prefix?t.prefix+n.getIdx(t):t.prefix+"/"+n.getIdx(t),e[i]?(r.isArray(e[i])||(e[i]=[e[i]]),e[i].push(t)):e[i]=t}}),e},dispose:function(){delete this.objs,delete this._idxProp}}),s=t.extend("beez.mvcr.Base",function(){},{getParent:function(){return this.manager.getParent(this)},deleteFromParent:function(){return this.manager.deleteFromParent(this)},getChildren:function(){return this.manager.getChildren(this)},getChildrenAll:function(){return this.manager.getChildrenAll(this)},alias:function(e){return this.manager.add(e,this)}});return{ManagerBase:o,Base:s}})}(this),function(){define("beez-mvcr/model",["require","exports","module","beez.core","backbone","beez-mvcr/base"],function(e){var t=e("beez.core"),r=t.vendor._,n=e("backbone"),i=t.vendor.$,o=e("beez-mvcr/base"),s=o.Base,a=o.ManagerBase,c=t.getLogger("beez.mvcr.model"),u=t.Bucks.extend("beez.mvcr.ModelManagerAsync",{initialize:function(e){this.manager=e,this.current=void 0,this.root=void 0},create:function(e,r,n,i){var o=this;return this.then(function(){var s=o.manager.create(e,r,n,i);return o.root=o.current=s,o.create=function(){throw new t.Error("create called more than once!")},s})},createCollection:function(e,r,n,i){var o=this;return this.then(function(){var s=o.manager.createCollection(e,r,n,i);return o.root=o.current=s,o.createCollection=function(){throw new t.Error("create called more than once!")},s})},child:function(e,n,i){var o=this;return this.then(function(){if(!o.root)throw new t.Error("No chain root exists. `create` first.");var s=o.manager.pathOf(o.current),a=o.manager.create(s,e,n,i);o.current=r.isArray(a)?a[0]:a})},parent:function(){var e=this;return this.then(function(){if(e.current=e.manager.getParent(e.current),!e.current)throw new t.Error("get parent failed")})},bro:function(e,t,r){return this.parent().child(e,t,r)},dispose:function(){c.trace(this.constructor.name,"dispose"),delete this.manager,delete this.current,this.root&&this.root.dispose&&this.root.dispose(),delete this.root}}),l=t.extend("beez.mvcr.ModelManager",a,{initialize:function(){var e=this;l.__super__.initialize.apply(this,arguments),this._sync=t.vendor.Backbone.sync,t.vendor.Backbone.sync=function(n,i,o){var s=t.config.ajax||{};r.defaults(o||(o={}),s,{dataType:"json",contentType:"application/json",emulateHTTP:!1,emulateJSON:!1}),e._sync.apply(this,arguments)}},async:function(){return new u(this)},root:function m(e){var r=new e(this),m=this.get("/@");if(m)throw new t.Error("root already exists!");if("@"!==r.midx)throw new t.Error('roots midx must be "@"');return this.add("/",r),r},create:function(e,n,i,o){if(!n||!r.isArray(n)&&"function"!=typeof n){var s="Model does not exist / does not be funciton. Specified prefix: "+e;throw new t.Error(s)}if(n instanceof g)throw new t.Error("Collection specified. Use #createCollection instead.");if(!e)throw new t.Error("No prefix specified. Creating:"+n.name);if(e.indexOf("/@")<0)throw new t.Error('prefix must started by "/@". Creating:'+n.name);if(!this.get(e))throw new t.Error("no parent exists. prefix: "+e+" , Please consider constructing in Controller and so on.");return r.isArray(n)?this._createArray(e,n,i,o):this._createObj(e,n,i,o)},_createObj:function(e,r,n,i){var o=new r(n,i,this);if(!this.isAddable(o))throw new t.Error("index does not exists in the Model. :"+o);return this.add(e,o),o},_createArray:function(e,n,i,o){i&&!r.isArray(i)&&(i=[i]),o&&!r.isArray(o)&&(o=[o]);var s=this,a=[];return r.each(n,function(e,t){var r=i?i[t]:void 0,n=o?o[t]:void 0;a.push(new e(r,n,s))}),r.each(a,function(e){if(!this.isAddable(e))throw new t.Error("index does not exist in the Model. :"+e)},this),this.add(e,a),a},createCollection:function(e,r,n,i){if(!r||"function"!=typeof r){var o="Collection does not exist / does not be funciton. Specified prefix: "+e;throw new t.Error(o)}if(!e)throw new t.Error("No prefix specified. Creating:"+r.name);if(e.indexOf("/@")<0)throw new t.Error('prefix must started by "/@". Creating:'+r.name);var s=new r(n,i,this);return this.add(e,s),s},_newAll:function(e,n,i){if(!e)throw new t.Error("ctor does not exist.");r.isArray(e)||(e=[e]),n&&!r.isArray(n)&&(n=[n]),i&&!r.isArray(i)&&(i=[i]);var o=[];return r.each(e,function(e,t){var r=n?n[t]:void 0,s=i?i[t]:void 0;o.push(new e(r,s))}),o},_decideBindedModel:function(e,n){var i,o,s;if(n)o=e;else{i=e,s=[],r.each(i,function(e){var t=this.getChildrenAll(e);s=s.concat(t)},this);var a=s.concat(i),c=r.reject(a,function(e){return e.isBinded()}),u=r.difference(a,c);r.each(u,function(e){throw new t.Error("a disposing model have some bindings. models cid: "+e.cid)}),o=c}return o},remove:function(e,t){var n=this.get(e);return n?(c.debug(this.constructor.name,"remove. path:",e),n.isCollection()?(this._decideBindedModel(n,!0).removeAll&&this._decideBindedModel(n,!0).removeAll(t),this.deleteFromParent(n),this):(n&&!r.isArray(n)&&(n=[n]),r.each(this._decideBindedModel(n),function(e){this.deleteFromParent(e)},this),r.each(this._decideBindedModel(n),function(e){e.dispose&&e.dispose()}),this)):(c.debug("Path of unmanaged become subject to deletion, I was skipped. path:",e),this)},ajax:function(e){var n=e.type,o=t.config.ajax||{},s=t.config.url&&t.config.url.api;if(r.defaults(e||(e={}),o,{dataType:"json",contentType:"application/json",emulateHTTP:!1,emulateJSON:!1,urlRoot:s||""}),/^(http|https):\/\//.test(e.url)||(e.url=e.urlRoot+e.url),e.data&&e.contentType&&0===e.contentType.indexOf("application/json")&&r.isObject(e.data)&&(e.data=JSON.stringify(e.data)),e.emulateJSON&&(e.contentType="application/x-www-form-urlencoded"),"GET"===e.type||e.emulateJSON||(e.processData=!1),e.emulateHTTP&&("PUT"===n||"DELETE"===n||"PATCH"===n)){e.type="POST",e.emulateJSON&&(e.data._method=n);var a=e.beforeSend;e.beforeSend=function(t,r){!e.emulateHTTP||"PUT"!==n&&"DELETE"!==n&&"PATCH"!==n||(r.headers?r.headers["X-HTTP-Method-Override"]=n:t.setRequestHeader("X-HTTP-Method-Override",n)),a&&a.apply(null,arguments)}}return i.ajax.call(null,e)},$get:function(e){return r.extend(e||(e={}),{type:"GET"}),this.ajax(e)},$post:function(e){return r.extend(e||(e={}),{type:"POST"}),this.ajax(e)},$put:function(e){return r.extend(e||(e={}),{type:"PUT"}),this.ajax(e)},$delete:function(e){return r.extend(e||(e={}),{type:"DELETE"}),this.ajax(e)},$patch:function(e){return r.extend(e||(e={}),{type:"PATCH"}),this.ajax(e)},dispose:function(){c.trace(this.constructor.name,"dispose");var e=this.getChildrenAll(this.objs);r.each(e,function(e){e.dispose()}),delete this.urlRoot,delete this._sync,l.__super__.dispose.apply(this,arguments)}}),h=t.Bucks.extend("beez.mvcr.ModelAsync",{initialize:function(e){this.model=e},fetch:function(e){var t=this.model;return this.then(function(n,i){e=e?r.clone(e):{},e.success=function(e,t){i(null,{model:e,res:t})},e.error=function(t,r){i(new Error(JSON.stringify({model:t,res:r,options:e})))},t.fetch(e)})},save:function(e,t,n){var i;null==e||r.isObject(e)?(i=e,n=t):null!=e&&((i={})[e]=t);var o=this.model;return this.then(function(e,t){n=n?r.clone(n):{},n.success=function(e,r){t(null,{model:e,res:r})},n.error=function(e,r){t(new Error(JSON.stringify({model:e,res:r,options:n})))},o.save(i,n)})},destroy:function(e){var t=this.model;return this.then(function(n,i){e=e?r.clone(e):{},e.success=function(e,t){i(null,{model:e,res:t})},e.error=function(t,r){i(new Error(JSON.stringify({model:t,res:r,options:e})))},t.destroy(e)})},dispose:function(){c.trace(this.constructor.name,"dispose"),delete this.model}}),d=t.extend("beez.mvcr.Model",s,n.Model.prototype,{constructor:function(e,n){var i=Array.prototype.slice.call(arguments);n=n||{};var o="";n.urlRoot?o=n.urlRoot:t.config&&t.config.url&&(o=t.config.url.api||""),n.urlRoot=o,r.extend(this,r.pick(n,["urlRoot"])),(1===i.length&&i[0].objs||2===i.length&&i[1].objs||3===i.length&&i[2].objs)&&(this.manager=i[i.length-1]),this.manager||c.debug("Manager can't be managed this model."),d.__super__.constructor.call(this,e,n)},initialize:function(){d.__super__.initialize.apply(this,arguments)},midx:void 0,async:function(){return new h(this)},isCollection:function(){return!1},isModel:function(){return!0},isBinded:function(){if(this._events){var e,t,n,i,o;for(i=r.keys(this._events),e=0,t=i.length;t>e;e++)if(n=i[e],o=this._events[n],o&&o.length>0)return!0}return!1},dispose:function(){c.trace(this.constructor.name,"dispose"),delete this.manager,delete this.cid,delete this.attributes,delete this.collection},remove:function(){throw new t.Error("Use Backbone.model.destroy() or Model.dipose() instead of this")}});d.extend=t.extendThis;var f=t.Bucks.extend("beez.mvcr.CollectionAsync",{initialize:function(e){this.collection=e},create:function(e,t){var r=this;return this.then(function(){return r.collection.create(e,t)})},remove:function(e,t){var r=this;return this.then(function(){return r.collection.remove(e,t)})},_reset:function(){var e=this;return this.then(function(){return e.collection._reset()})},dispose:function(){c.trace(this.constructor.name,"dispose"),delete this.collection}}),g=t.extend(s,n.Collection.prototype,{constructor:function(e,r,n){this.model||(this.model=d),this.urlRoot=function(){var e="";return t.config&&t.config.url&&(e=t.config.url.api||""),e}(),this.manager=n;var i=arguments;3<=arguments.length&&(i=Array.prototype.slice.call(arguments,0,arguments.length-1)),g.__super__.constructor.apply(this,i)},initialize:function(){g.__super__.initialize.apply(this,arguments)},midx:void 0,async:function(){return new f(this)},isCollection:function(){return!0},isModel:function(){return!1},remove:function(e){return g.__super__.remove.apply(this,arguments),e=r.isArray(e)?e.slice():[e],r.each(e,function(e){e.dispose&&e.dispose()}),this},removeAll:function(e){return this.remove(this.models,e)},_reset:function(){this.length=0,r.each(this.models,function(e){e.dispose&&e.dispose()}),this.models=[],this._byId={}},isBinded:function(){if(this._events){var e,t,n,i,o;for(i=r.keys(this._events),e=0,t=i.length;t>e;e++)if(n=i[e],o=this._events[n],o&&o.length>0)return!0}return!1},dispose:function(){c.trace(this.constructor.name,"dispose"),r.each(this.models,function(e){e.dispose&&e.dispose()}),delete this.manager,delete this.comparator,delete this.length,delete this.models,delete this._byId}});return g.extend=t.extendThis,{Model:d,Collection:g,ModelManager:l,ModelManagerAsync:u}})}(this),function(){define("beez-mvcr/modic",["require","exports","module","beez.core","backbone","beez-mvcr/model"],function(e){var t=e("beez.core");t.vendor._,e("backbone");var r=e("beez-mvcr/model"),n=r.Model.extend("beez.mvcr.Modic",{midx:void 0,lRoot:function(){throw new t.Error("not allowed to use this function.")},url:function(){throw new t.Error("not allowed to use this function.")},async:function(){throw new t.Error("not allowed to use this function.")},fetch:function(){throw new t.Error("not allowed to use this function.")},save:function(){throw new t.Error("not allowed to use this function.")}});return{Modic:n}})}(this),function(){define("beez-mvcr/view",["require","exports","module","beez.core","backbone","beez-mvcr/base"],function(e){var t=e("beez.core"),r=t.vendor._,n=e("backbone"),i=e("beez-mvcr/base"),o=i.Base,s=i.ManagerBase,a=t.getLogger("beez.mvcr.view"),c=t.Bucks.extend("beez.mvcr.ViewManagerAsync",{initialize:function(e){this.manager=e},root:function d(d){var e=this;return this.then(function(){return e.manager.root(d)})},create:function(e,t,n){var i=this;return this.then(function(){var o=i.manager.create(e,t,n),s=r.isArray(o)?o[0]:o;return s})},child:function(e,t){var n=this;return this.then(function(i){var o=n.manager.pathOf(i),s=n.manager.create(o,e,t);return i=r.isArray(s)?s[0]:s})},parent:function(){var e=this;return this.then(function(r){var n=e.manager.getParent(r);if(n)throw new t.Error("get parent failed. current: "+r);return r=n})},bro:function(e,t){return this.parent().child(e,t)},dispose:function(){a.trace(this.constructor.name,"dispose"),delete this.manager,delete this.current,delete this.root}}),u=t.extend("beez.mvcr.ViewManager",s,{initialize:function(){u.__super__.initialize.apply(this,arguments)},async:function(){return new c(this)},root:function f(e){this.add("/",new function(){this.vidx="@"});var r=new e(this),n=this.getChildren(this.get("/@"));this.remove("/@");var f=this.get("/@");if(f)throw new t.Error("root already exists!");if("@"!==r.vidx)throw new t.Error('roots vidx must be "@"');this.add("/",r);for(var i=0;i<n.length;i++)this.add("/@",n[i]);return r},create:function(e,n,i){if(!n||!r.isArray(n)&&"function"!=typeof n)throw new t.Error("View does not exist / does not be funciton. Specified prefix: "+e);if(!e)throw new t.Error("No prefix specified. Creating:"+n.name);if(e.indexOf("/@")<0)throw new t.Error('prefix must started by "/@". Creating:'+n.name);if(!this.get(e))throw new t.Error("no parent exists. prefix: "+e+" , Please consider constructing view in Controller, or in #beforeOnce and so on.");return r.isArray(n)?this._createArray(e,n,i):this._createObj(e,n,i)},_createObj:function(e,r,n){var i=new r(this,n);if(!this.isAddable(i))throw new t.Error("index does not exists in the View. :"+i);return this.add(e,i),i},_createArray:function(e,n,i){var o=this;i&&!r.isArray(i)&&(i=[i]);var s=[];return r.each(n,function(e,t){var r=i?i[t]:void 0,n=new e(o,r);s.push(n)}),r.each(s,function(e){if(!this.isAddable(e))throw new t.Error("index does not exists in the View. :"+e)},this),this.add(e,s),s},remove:function(){u.__super__.remove.apply(this,arguments)},dispose:function(){a.trace(this.constructor.name,"dispose");var e=this.getChildrenAll(this.objs);r.each(e,function(e){e.dispose()}),u.__super__.dispose.apply(this,arguments)}}),l=t.Bucks.extend("beez.mvcr.ViewAsync",{initialize:function(e){this._root=e},_render:function(e){return this.then(function(){return e}),e.state.isBeforeOnce||this.then(function(e,t){return e.visible?e.beforeOnce.length?(e.beforeOnce(function(){e.state.isBeforeOnce=!0,t(null,e)}),void 0):(e.beforeOnce(),e.state.isBeforeOnce=!0,t(null,e),void 0):(a.debug("view",e.vidx,"is not visible. skip `beforeOnce`."),t(null,e),void 0)}),this.then(function(e,t){return e.visible?e.before.length?(e.before(function(){t(null,e)}),void 0):(e.before(),t(null,e),void 0):(a.debug("view",e.vidx,"is not visible. skip `before`."),t(null,e),void 0)}),this.then(function(e,t){return e.visible?e.render.length?(e.render(function(){t(null,e)}),void 0):(e.render(),t(null,e),void 0):(a.debug("view",e.vidx,"is not visible. skip `render`."),t(null,e),void 0)}),this.then(function(e,t){return e.visible?e.after.length?(e.after(function(){t(null,e)}),void 0):(e.after(),t(null,e),void 0):(a.debug("view",e.vidx,"is not visible. skip `after`."),t(null,e),void 0)}),e.state.isAfterOnce||this.then(function(e,t){return e.visible?e.afterOnce.length?(e.afterOnce(function(){e.state.isAfterOnce=!0,t(null,e)}),void 0):(e.afterOnce(),e.state.isAfterOnce=!0,t(null,e),void 0):(a.debug("view",e.vidx,"is not visible. skip `afterOnce`."),t(null,e),void 0)}),this},_remove:function(e){return this.then(function(){return e.remove(),e})},show:function(e){if(!this._root)throw new t.Error("render root is not set. initialize renderer with root view parameter.");return this._show(this._root,e)},_show:function(e,t){if(void 0===t&&(t=!0),r.isArray(e)){if(r.isEmpty(e))return this;e.sort(function(e,t){return e.order<t.order?-1:e.order>t.order?1:0});var n=r.map(e,function(e){return function(r,n,i){if(r)throw r;(new l)._show(e,t).end(function(e){i(e,void 0)})}});this.waterfall(n)}else a.debug("showing",e.vidx),this._render(e,t);return t&&this.then(function(e,n){if(!e)return n(null,e);var i=e.getChildren();return r.isEmpty(i)?n(null,e):(new l)._show(i,t).end(n)}),this},hide:function(e){if(!this._root)throw new t.Error("render root is not set. initialize renderer with root view parameter.");return this._hide(this._root,e)},_hide:function(e,t){if(void 0===t&&(t=!0),r.isArray(e)){var n=r.map(e,function(e){return function(r,n,i){if(r)throw r;(new l)._hide(e,t).end(function(e){i(e,void 0)})}});this.waterfall(n)}else a.debug("hiding",e.vidx),this._remove(e);return t&&this.then(function(e,n){if(!e)return n(null,e);var i=e.getChildren();return r.isEmpty(i)?n(null,e):(new l)._hide(i,t).end(n)}),this},dispose:function(){a.trace(this.constructor.name,"dispose"),delete this._root}}),h=t.extend("beez.mvcr.View",o,n.View.prototype,{constructor:function(){if(arguments.length<1)throw new t.Error("In order to create a View, requires one arguments.");this.manager=arguments[0],this.state={isBeforeOnce:!1,isAfterOnce:!1},this.visible=!0,h.__super__.constructor.apply(this,Array.prototype.slice.call(arguments,1))},initialize:function(){h.__super__.initialize.apply(this,arguments)},vidx:void 0,el:void 0,order:0,beforeOnce:t.none,before:t.none,after:t.none,afterOnce:t.none,async:function(){return new l(this)},isRendered:function(){return!!this.el&&!!this.el.parentElement},setVisible:function(e){if("boolean"!=typeof e)throw t.Error("typeof visible invalid. should be boolean.");return this.visible=e,this},dispose:function(){a.trace(this.constructor.name,"dispose"),this.remove(),h.__super__.undelegateEvents.apply(this,arguments),delete this.manager,delete this.state,delete this.visible,delete this.cid,delete this.options,delete this.$el,delete this.model,delete this.collection,delete this.el,delete this.attributes,delete this.className,delete this.tagName},remove:function(){h.__super__.remove.apply(this,arguments)}});return h.extend=t.extendThis,{View:h,ViewAsync:l,ViewManager:u,ViewManagerAsync:c}})}(this),function(){define("beez-mvcr/controller",["require","exports","module","beez.core","beez.mvcr","beez.i18n"],function(e){var t=e("beez.core");e("beez.mvcr"),e("beez.i18n");var r=t.getLogger("beez.mvcr.controller"),n=t.vendor._,i=t.Bucks.extend("beez.mvcr.ControllerManagerAsync",{initialize:function(e){this.manager=e},create:function(e,n){var i=this;return this.then(function(r,o){if(!n||"function"!=typeof n)throw new t.Error("Controller does not exist / does not be funciton. Specified name: "+e);if(i.manager.controllers[e])throw new t.Error("It is a singleton in the module. name:"+e);var s=new n;i.manager.controllers[e]=s,o(r,i.manager.controllers[e])}).then(function(e,t){e.loadCSS(function(){t(null,e)})}).then(function(e,t){e.loadI18n(function(n){n&&(r.error("i18n load error. ",n.message),r.debug(n.stack)),t(n,e)})})},dispose:function(){r.trace(this.constructor.name,"dispose"),delete this.manager}}),o=t.extend("beez.mvcr.ControllerManager",function(){return this.initialize()},{initialize:function(){this.controllers={}},async:function(){return new i(this)},remove:function(e){var t=this.get(e);return t?(delete this.controllers[e],this):this},get:function(e){return this.controllers[e]},dispose:function(){r.trace(this.constructor.name,"dispose"),delete this.controllers}}),s=t.extend("beez.mvcr.Controller",function(){this.initialize.apply(this,arguments)},{initialize:function(){},i18n:function(){},loadI18n:function(i){t.i18n||t.createI18n();var o=this;if(t.utils.is("Object",this.i18n)){var s=[],a=[];n.each(this.i18n,function(e,t){s.push(t),a.push(e)}),e(a,function(){for(var e=Array.prototype.slice.call(arguments),n=0;n<e.length;n++){var o={};o[s[n]]=e[n],t.i18n.add(o),r.debug("i18n file loaded. path:",a[n])}i&&i(null)},function(e){i&&i(e)})}else t.utils.is("Function",this.i18n)?(new t.Bucks).add(function(e,t,r){0<o.i18n.length?o.i18n(function(e,t){r(e,t)}):r(null,o.i18n())}).add(function(e,r){r&&t.i18n.add(r),i&&i(e,r)}).end():i&&i(new Error("The Controller.i18n, please be defined in Function."));return this},loadCSS:function(e){var r=this.css;if(!r||r.length<1)return e&&e();var i=n.map(r,function(e){return function(r,n,i){t.manager.css.async().load(e).end(function(e,t){i(r,t[0])},function(e){i(e)})}}),o=new t.Bucks;return o.parallel(i).end(function(t,r){e&&e(t,r)}),this},dispose:function(){r.trace(this.constructor.name,"dispose"),delete this.constructor.prototype.css}});return s.extend=t.extendThis,{Controller:s,ControllerManager:o,ControllerManagerAsync:i}})}(this),function(){define("beez-mvcr/router",["require","exports","module","beez.core","beez.mvcr","backbone"],function(e){var t=e("beez.core");e("beez.mvcr");var r=t.getLogger("beez.mvcr.router"),n=t.vendor._,i=e("backbone"),o={initialize:function(){this.router=void 0,this.setuped=!1},setup:function(i,o){var s=this;if(this.setuped)throw new t.Error("Already been executed once. If you want to add a route, please refer to the function add().");var a=t.config.router||{},c=n.extend(a,i);if(this.router)return this;this.router=o||new t.Router;for(var u=n.keys(c),l=0;l<u.length;l++){var h=u[l],d=c[h];this.router.route(d.route,d.name,function(n){function i(){if(!c.hasOwnProperty(n))throw new t.Error("route map key does not exist. name: "+n);var i=c[n],o=Array.prototype.slice.call(arguments);r.debug("router.proxy",i);var a=new t.Bucks;a.then(function(e,n){if(t.manager.c.get(i.xpath))return n();if(i.async){if(2!==s.router.firstBefore.length)throw new t.Error("You should pass a callback function in arguments in case of async setting is true. firestBefore(data, callback)");r.trace("run controller firstBefore function(async). data:",i),s.router.firstBefore(i,function(e,t){n(null,t)})}else r.trace("run controller firstBefore function(sync). data:",i),s.router.firstBefore(i),n()}),a.then(function(n,o){e([i.require],function(e){r.debug("controller.exec",i.xpath);var n=t.manager.c.get(i.xpath),s={};return n?(s.isFirstBefore=!0,o(null,{Controller:e,controller:n,state:s}),void 0):(t.manager.c.async().create(i.xpath,e).then(function(t){s.isFirstBefore=!1,o(null,{Controller:e,controller:t,state:s})}).end(),void 0)})}),a.then(function(e,n){var a=e.controller,c=e.Controller;if(i.state=e.state,!a[i.name])throw new t.Error('"'+i.name+'" to Controller I is undefined.');if(i.async){if(3!==s.router.before.length)throw new t.Error("You should pass a callback function in arguments in case of async setting is true. before(data, Controller, callback)");r.trace("run controller before function(async). data:",i),s.router.before(i,c,function(){if(o.push(function(){if(3!==s.router.after.length)throw new t.Error("You should pass a callback function in arguments in case of async setting is true. after(data, Controller, callback)");r.trace("run controller after function(async). data:",i),s.router.after(i,c,function(){n()})}),a[i.name].length!==o.length)throw new t.Error('"Controller.'+i.name+'" function should takes '+o.length+" arguments. ("+a[i.name].length+")");a[i.name].apply(a,o)})}else r.trace("run controller before function(sync). data:",i),s.router.before(i,c),a[i.name].apply(a,o),r.trace("run controller after function(sync). data:",i),s.router.after(i,c),n()}),a.end()}return i}(h))}this.setuped=!0},navigate:function(e,r){if(!this.setuped||!this.router)throw new t.Error('Initialization has not been performed even once. Please do a "setup()".');return this.router.navigate(e,r)},dispose:function(){r.trace(this.constructor.name,"dispose"),this.router&&this.router.dispose&&this.router.dispose(),delete this.router,delete this.setuped}},s=t.extend("beez.mvcr.RouterManager",function(){return this.initialize()},o),a=t.extend("beez.mvcr.Router",i.Router,{constructor:function(){a.__super__.constructor.apply(this,arguments)},initialize:function(){a.__super__.initialize.apply(this,arguments)},firstBefore:function(e,t){t&&t()},before:function(e,t,r){r&&r()},after:function(e,t,r){r&&r()},dispose:function(){r.trace(this.constructor.name,"dispose")}});return a.extend=t.extendThis,{Router:a,RouterManager:s}})}(this),function(){define("beez-mvcr/cssmanager",["require","exports","module","beez.core"],function(e){var t=e("beez.core"),r=t.getLogger("beez.mvcr.cssmanager"),n=t.vendor._,i=t.vendor.$,o=function(e){var t=document.styleSheets,r=n.find(t,function(t){var r=t.href;return r&&-1!==r.indexOf(e)});return r&&r.rules&&r.rules.length>0},s=function(e){var t=document.styleSheets,r=n.find(t,function(t){var r=t.href;return r&&-1!==r.indexOf(e)});return!!r},a=t.Bucks.extend("beez.mvcr.CSSManagerAsync",{initialize:function(e){this.manager=e,this._path="",this._intervalId=void 0,this._timeoutId=void 0,this.INTERVAL=t.config.manager&&t.config.manager.css&&t.config.manager.css.interval||50,this.TIMEOUT=t.config.manager&&t.config.manager.css&&t.config.manager.css.timeout||1e4},load:function(e){var o=this,a=this._path=e;if(e.match(/^(http|https):\/\/.+$/)||(a=this._path=this.manager.name2path(e)),!a)return this.empty();if(this.manager.isLoaded(a))return r.debug("path:",a,"already exists"),a=void 0,this.empty();var c='<link rel="stylesheet" href="'+n.escape(a)+'" ></link>';return i("head").append(c),this.then(function(e,n){o._intervalId=setInterval(function(){s(a)&&(o.abort(),r.debug("load finished. path:",a),n())},o.INTERVAL),o._timeoutId=setTimeout(function(){o.abort(),n(new t.Error("loading timed out. path:"+a))},o.TIMEOUT)})},remove:function(e){var t=this;return this.then(function(){return t.manager.remove(e)})},abort:function(){clearTimeout(this._timeoutId),clearInterval(this._intervalId),delete this._timeoutId,delete this._intervalId,delete this.INTERVAL,delete this.TIMEOUT},dispose:function(){r.trace(this.constructor.name,"dispose"),delete this.manager,delete this._path,this.abort()}}),c=t.extend("beez.mvcr.CSSManager",function(){return this.initialize()},{initialize:function(){this._basePath="",t.config.url&&t.config.url.base&&(this._basePath=t.config.url.base,this._basePath.replace(/\/$/,""))},name2path:function(e){var t="";return t=this._basePath?0===e.indexOf("/")?this._basePath+e:this._basePath+"/"+e:e},async:function(){return new a(this)},remove:function(e){var t=i("link[rel=stylesheet]");return t.each(function(){-1!==this.href.indexOf(e)&&(r.debug("remove finished. name:",e,"path:",this.href),i(this).remove())}),this},isExists:o,isLoaded:s,dispose:function(){r.trace(this.constructor.name,"dispose"),delete this._basePath}});return{CSSManager:c,CSSManagerAsync:a}})}(this),function(){define("beez-mvcr/imagemanager",["require","exports","module","beez.core","beez.utils"],function(e){var t=e("beez.core");e("beez.utils");var r=t.vendor._,n=t.vendor.$,i=t.getLogger("beez.mvcr.imagemanager"),o="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAMAAAAoyzS7AAAABlBMVEX///8AAABVwtN+AAAAAXRSTlMAQObYZgAAAA1JREFUeNoBAgD9/wAAAAIAAVMrnDAAAAAASUVORK5CYII=",s=0,a=function(){return"__beez_manager_image_uid_"+s++},c=t.extend("beez.mvcr.ImagePool",function(e,t){return this.initialize(e,t)},{initialize:function(e,t){this.options=t||{},this.limit=e,this._total=0,this._num_used=0,this._using={},this._unused=[]
},create:function(e){var r;if(e=e||{},this._unused.length>0)r=this._unused.pop();else{if(this.limit>0&&this._total>=this.limit)throw new t.Error("image pool limit exceeds!");r=new Image,r.__beez_manager_image_uid=a(),this._total++}e.crossOrigin?r.crossOrigin=e.crossOrigin:this.options.crossOrigin&&(r.crossOrigin=this.options.crossOrigin),this._num_used++,this._using[r.__beez_manager_image_uid]=r;var n=this;return r.release=function(){this.crossOrigin=null,this.src=o,n._using&&delete n._using[this.__beez_manager_image_uid],n._unused&&n._unused.push(this),n._num_used&&n._num_used--,delete this.release},r},living:function(){return this._num_used},peak:function(){return this._total},waiting:function(){return this._unused.length},dispose:function(){i.trace(this.constructor.name,"dispose");for(var e in this._using)this._using[e].release();for(delete this._using;this._unused.length>0;){var t=this._unused.pop();delete t.__beez_manager_image_uid}delete this._unused,delete this._num_used,delete this._total,delete this._limit}}),u=t.Bucks.extend("beez.mvcr.ImageManagerAsync",{initialize:function(e){this.imageManager=e},loadOne:function(e,r){var i=this.imageManager.create(r),o=this;return this.add(function(r,s,a){var c=n(i),u=function(){c.off(),a(null,i)},l=function(){var e=i.src;c.off(),i.release(),a(new t.Error("error on load image. src:"+e))},h=function(){var e=i.src;c.off(),i.release(),a(new t.Error("image loading aborted. src:"+e))};c.on("load",u),c.on("error",l),c.on("abort",h);var d=o.imageManager.imageUrl(e);i.src=d})},load:function(e,n){if(r.isString(e))e=[e];else if(!r.isArray(e))throw new t.Error("url can be String or Array of string.");if(n=n||{},!r.isArray(n)){if(!r.isObject(n))throw new t.Error("options can be Object or Array of object.");n=[n]}var i=this,o=r.map(e,function(e,t){return function(r,o,s){new u(i.imageManager).loadOne(e,n[t]).end(function(e,t){s(e,t[0])},function(e){s(e)})}});return this.parallel(o)},dispose:function(){delete this.imageManager}}),l=t.extend("beez.mvcr.ImageManager",function(e){return this.initialize(e)},{initialize:function(e){var t=e&&e.size?e.size:0,r=e&&e.pool?e.pool:{};this.pool=new c(t,r)},imageUrl:function(e){return e.replace("${ratio}",10*t.utils.pixelRatio)},create:function(e){return this.pool.create(e)},living:function(){return this.pool.living()},peak:function(){return this.pool.peak()},waiting:function(){return this.pool.waiting()},load:function(e,t){return new u(this).load(e,t)},loadOne:function(e,t){return new u(this).loadOne(e,t)},dispose:function(){i.trace(this.constructor.name,"dispose"),this.pool.dispose(),delete this.pool}});return{ImageManager:l,ImageManagerAsync:u}})}(this),function(){define("beez.mvcr",["require","exports","module","beez.core","handlebars","beez-mvcr/model","beez-mvcr/modic","beez-mvcr/view","beez-mvcr/controller","beez-mvcr/router","beez-mvcr/cssmanager","beez-mvcr/imagemanager","beez-mvcr/base","backbone","beez-mvcr/model","beez-mvcr/view","beez-mvcr/controller","beez-mvcr/router","beez-mvcr/cssmanager","beez-mvcr/imagemanager"],function e(t){var r=t("beez.core"),n=r.getLogger("beez.mvcr");if(r.mvcr)return n.debug("beez.mvcr already defined."),r.mvcr;var i=t("handlebars");r.getTemplate=function(e){return i.templates[e]};var e={initialize:function(){var e=t("beez-mvcr/model"),r=t("beez-mvcr/modic"),n=t("beez-mvcr/view"),i=t("beez-mvcr/controller"),o=t("beez-mvcr/router"),s=t("beez-mvcr/cssmanager"),a=t("beez-mvcr/imagemanager"),c=t("beez-mvcr/base");this.Model=e.Model,this.ModelManager=e.ModelManager,this.ModelManagerAsync=e.ModelManagerAsync,this.Collection=e.Collection,this.Modic=r.Modic,this.View=n.View,this.ViewAsync=n.ViewAsync,this.ViewManager=n.ViewManager,this.ViewManagerAsync=n.ViewManagerAsync,this.Controller=i.Controller,this.ControllerManager=i.ControllerManager,this.ControllerManagerAsync=i.ControllerManagerAsync,this.Router=o.Router,this.RouterManager=o.RouterManager,this.CSSManager=s.CSSManager,this.CSSManagerAsync=s.CSSManagerAsync,this.ImageManager=a.ImageManager,this.ImageManagerAsync=a.ImageManagerAsync,this.ManagerBase=c.ManagerBase,this.Base=c.Base}},o=r.extend("beez.MVCR",function(){return this.initialize()},e),s=new o;r.mvcr=s,r.Model=s.Model,r.Collection=s.Collection,r.Modic=s.Modic,r.View=s.View,r.Controller=s.Controller,r.Router=s.Router;var a=t("backbone");r.history=a.history;var c=r.config.manager||{},u={initialize:function(){this.setuped=!1,this.model=void 0,this.m=void 0,this.view=void 0,this.v=void 0,this.controller=void 0,this.c=void 0,this.router=void 0,this.r=void 0,this.css=void 0,this.image=void 0},setup:function(e){if(this.setuped)return this;if(e=e||{},this.setuped=!0,e.model)this.model=e.model;else{var r=t("beez-mvcr/model");this.model=new r.ModelManager("midx")}if(this.m=this.model,e.view)this.view=e.view;else{var n=t("beez-mvcr/view");this.view=new n.ViewManager("vidx")}if(this.v=this.view,e.controller)this.controller=e.controller;else{var i=t("beez-mvcr/controller");this.controller=new i.ControllerManager}if(this.c=this.controller,e.router)this.router=e.router;else{var o=t("beez-mvcr/router");this.router=new o.RouterManager}if(this.r=this.router,e.css)this.css=e.css;else{var s=t("beez-mvcr/cssmanager");this.css=new s.CSSManager}if(e.image)this.image=e.image;else{var a=t("beez-mvcr/imagemanager");this.image=new a.ImageManager(c.image)}return this}},l=r.extend("beez.Manager",function(){return this.initialize()},u),h=new l;return s.manager=h,r.manager=s.manager,r.mvcr})}(this);