-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsirius.min.js
160 lines (160 loc) · 68.8 KB
/
sirius.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
Sirius.js v1.3.3
(c) 2014-2020 fntz
license: MIT
*/
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.arrayIteratorImpl=function(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}};$jscomp.arrayIterator=function(a){return{next:$jscomp.arrayIteratorImpl(a)}};$jscomp.makeIterator=function(a){var b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];return b?b.call(a):$jscomp.arrayIterator(a)};$jscomp.arrayFromIterator=function(a){for(var b,c=[];!(b=a.next()).done;)c.push(b.value);return c};
$jscomp.arrayFromIterable=function(a){return a instanceof Array?a:$jscomp.arrayFromIterator($jscomp.makeIterator(a))};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;$jscomp.objectCreate=$jscomp.ASSUME_ES5||"function"==typeof Object.create?Object.create:function(a){var b=function(){};b.prototype=a;return new b};$jscomp.underscoreProtoCanBeSet=function(){var a={a:!0},b={};try{return b.__proto__=a,b.a}catch(c){}return!1};
$jscomp.setPrototypeOf="function"==typeof Object.setPrototypeOf?Object.setPrototypeOf:$jscomp.underscoreProtoCanBeSet()?function(a,b){a.__proto__=b;if(a.__proto__!==b)throw new TypeError(a+" is not extensible");return a}:null;
$jscomp.inherits=function(a,b){a.prototype=$jscomp.objectCreate(b.prototype);a.prototype.constructor=a;if($jscomp.setPrototypeOf){var c=$jscomp.setPrototypeOf;c(a,b)}else for(c in b)if("prototype"!=c)if(Object.defineProperties){var d=Object.getOwnPropertyDescriptor(b,c);d&&Object.defineProperty(a,c,d)}else a[c]=b[c];a.superClass_=b.prototype};
$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){a!=Array.prototype&&a!=Object.prototype&&(a[b]=c.value)};$jscomp.getGlobal=function(a){a=["object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global,a];for(var b=0;b<a.length;++b){var c=a[b];if(c&&c.Math==Math)return c}throw Error("Cannot find global object");};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_";
$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.SymbolClass=function(a,b){this.$jscomp$symbol$id_=a;$jscomp.defineProperty(this,"description",{configurable:!0,writable:!0,value:b})};$jscomp.SymbolClass.prototype.toString=function(){return this.$jscomp$symbol$id_};
$jscomp.Symbol=function(){function a(c){if(this instanceof a)throw new TypeError("Symbol is not a constructor");return new $jscomp.SymbolClass($jscomp.SYMBOL_PREFIX+(c||"")+"_"+b++,c)}var b=0;return a}();
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var a=$jscomp.global.Symbol.iterator;a||(a=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("Symbol.iterator"));"function"!=typeof Array.prototype[a]&&$jscomp.defineProperty(Array.prototype,a,{configurable:!0,writable:!0,value:function(){return $jscomp.iteratorPrototype($jscomp.arrayIteratorImpl(this))}});$jscomp.initSymbolIterator=function(){}};
$jscomp.initSymbolAsyncIterator=function(){$jscomp.initSymbol();var a=$jscomp.global.Symbol.asyncIterator;a||(a=$jscomp.global.Symbol.asyncIterator=$jscomp.global.Symbol("Symbol.asyncIterator"));$jscomp.initSymbolAsyncIterator=function(){}};$jscomp.iteratorPrototype=function(a){$jscomp.initSymbolIterator();a={next:a};a[$jscomp.global.Symbol.iterator]=function(){return this};return a};
$jscomp.iteratorFromArray=function(a,b){$jscomp.initSymbolIterator();a instanceof String&&(a+="");var c=0,d={next:function(){if(c<a.length){var e=c++;return{value:b(e,a[e]),done:!1}}d.next=function(){return{done:!0,value:void 0}};return d.next()}};d[Symbol.iterator]=function(){return d};return d};
$jscomp.polyfill=function(a,b,c,d){if(b){c=$jscomp.global;a=a.split(".");for(d=0;d<a.length-1;d++){var e=a[d];e in c||(c[e]={});c=c[e]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&$jscomp.defineProperty(c,a,{configurable:!0,writable:!0,value:b})}};$jscomp.polyfill("Array.prototype.keys",function(a){return a?a:function(){return $jscomp.iteratorFromArray(this,function(a){return a})}},"es6","es3");
$jscomp.checkStringArgs=function(a,b,c){if(null==a)throw new TypeError("The 'this' value for String.prototype."+c+" must not be null or undefined");if(b instanceof RegExp)throw new TypeError("First argument to String.prototype."+c+" must not be a regular expression");return a+""};
$jscomp.polyfill("String.prototype.startsWith",function(a){return a?a:function(a,c){var b=$jscomp.checkStringArgs(this,a,"startsWith");a+="";var e=b.length,f=a.length;c=Math.max(0,Math.min(c|0,b.length));for(var g=0;g<f&&c<e;)if(b[c++]!=a[g++])return!1;return g>=f}},"es6","es3");var Adapter,ComputedField,Sirius,VanillaJsAdapter;Sirius={VERSION:"1.0.3"};
Adapter=function(){var a=function(){};a.prototype.bind=function(a,c,d,e){};a.prototype.off=function(a,c,d){};a.prototype.fire=function(a,c,d){};a.prototype.get_properties=function(a,c){};a.prototype.get_attr=function(a,c){};a.prototype.swap=function(a,c){};a.prototype.append=function(a,c){};a.prototype.prepend=function(a,c){};a.prototype.clear=function(a){};a.prototype.set_attr=function(a,c,d){};a.prototype.all=function(a){return"object"===typeof a&&1===a.nodeType||9===a.nodeType?a:document.querySelectorAll(a)};
a.prototype.get=function(a){return document.querySelector(a)};a.prototype.as_string=function(a){if(a===document)return"document";if("[object String]"===Object.prototype.toString.call(a))return a;try{if(Array.isArray(a)&&1<a.size){var b=a.map(function(a){return a.tagName+"."+a.className});return b.slice(0,3).join(", ")}return a.tagName+"."+id}catch(d){return a}};a.prototype._adapter_name="Adapter";return a}.call(this);
VanillaJsAdapter=function(){var a=function(){return Adapter.apply(this,arguments)||this};$jscomp.inherits(a,Adapter);a.prototype._get_element_from_selector=function(a){if("object"===typeof a&&1===a.nodeType)return a;var b=this.all(a);if(0===b.length)throw Error("Selector `"+a+"` not found");return b[0]};a.prototype.bind=function(a,c,d,e){var b,g;if(null===c||c===a)a.addEventListener(d,e);else if("object"===typeof c&&1===c.nodeType)c.addEventListener(d,e);else for(a=this.all(c),c=b=0,g=a.length;0<=
g?0<=b&&b<g:0>=b&&b>g;c=0<=g?++b:--b)a.item(c).addEventListener(d,e)};a.prototype.off=function(a,c,d){var b,f;a=this.all(a);var g=b=0;for(f=a.length;0<=f?0<=b&&b<f:0>=b&&b>f;g=0<=f?++b:--b)a.item(g).removeEventListener(c,d)};a.prototype.fire=function(a,c,d){for(var b=[],f=2;f<arguments.length;++f)b[f-2]=arguments[f];f=document.createEvent("CustomEvent");f.initCustomEvent(c,!1,!0,b);document.dispatchEvent(f)};a.prototype.get_properties=function(a,c){var b;a=a.target;var e=[];var f=0;for(b=c.length;f<
b;f++){var g=c[f];e.push(this.get_attr(a,g))}return e};a.prototype.get_attr=function(a,c){a=this._get_element_from_selector(a);var b=a.getAttribute(c);return null!=b?"checked"===c||"selected"===c?"false"===b?!1:!0:b:a[c]};a.prototype.swap=function(a,c){a=this._get_element_from_selector(a);var b=a.tagName;"INPUT"===b||"TEXTAREA"===b||"SELECT"===b?a.value=c:a.textContent=c};a.prototype.set_attr=function(a,c,d){this._get_element_from_selector(a).setAttribute(c,d)};a.prototype.append=function(a,c){a=
this._get_element_from_selector(a);a.textContent+=c};a.prototype.prepend=function(a,c){a=this._get_element_from_selector(a);a.textContent=c+a.textContent};a.prototype.clear=function(a){a=this._get_element_from_selector(a);var b=a.tagName;"INPUT"===b||"TEXTAREA"===b?a.value="":a.textContent=""};a.prototype.text=function(a){a=this._get_element_from_selector(a);var b=a.tagName;return"INPUT"===b||"TEXTAREA"===b||"SELECT"===b?a.value:a.innerText?a.innerText:a.textContent};a.prototype._adapter_name="VanillaJs";
return a}.call(this);
Sirius.Logger=function(){var a=function(a){var b=this;this.log_source=a;this._log_queue=[];if(!Sirius.Logger.Configuration._is_initialized){var c=setInterval(function(){return f()},100);var f=function(){var a;if(Sirius.Logger.Configuration._is_initialized){var d=b._log_queue;var f=0;for(a=d.length;f<a;f++){var e=d[f];b._write(e.level,e.message)}return clearInterval(c)}}}};a.build=function(a){return new Sirius.Logger(a)};a.prototype.debug=function(a){return this._write(Sirius.Logger.Debug,a)};a.prototype.info=
function(a){return this._write(Sirius.Logger.Info,a)};a.prototype.warn=function(a){return this._write(Sirius.Logger.Warn,a)};a.prototype.error=function(a){return this._write(Sirius.Logger.Error,a)};a.prototype._write=function(a,b){if(Sirius.Logger.Configuration._is_initialized){if(a.gte(Sirius.Logger.Configuration.minimum_log_level))return Sirius.Logger.Configuration.log_function(a.get_value().toUpperCase(),this.log_source,b)}else return this._log_queue.push[{level:a,message:b}]};a.prototype.log_source=
null;var b=function(a,b){this.value=a;this.weight=b};b.prototype.gte=function(a){return this.weight>=a.weight};b.prototype.get_value=function(){return this.value};a.Debug=new b("debug",10);a.Info=new b("info",20);a.Warn=new b("warn",30);a.Error=new b("error",40);a.NoLog=new b("no-log",100);a.Levels=[a.Debug,a.Info,a.Warn,a.Error];a.Default={enable_logging:!1,minimum_log_level:a.Debug.get_value(),default_log_function:function(a,b,e){return console&&console.log?console.log(a+" ["+b+"]: "+e):alert("Not supported `console`. You should define own `logger` function for a Sirius.Application")}};
a.Configuration={minimum_log_level:null,log_function:null,enable_logging:null,_is_initialized:!1,configure:function(b){b=void 0===b?{}:b;var c;var e=b.enable_logging||a.Default.enable_logging;if((c=b.minimum_log_level)&&!this.is_valid_level(c))throw b=a.Levels.map(function(a){return a.get_value()}),Error("Invalid 'minimum_log_level' value: '"+c+"', available options are: "+b.join(", "));c=c||a.Default.minimum_log_level;this.minimum_log_level=e?this._get_logger_from_input(c):a.NoLog;this.enable_logging=
e;if(b.log_to){if(!Sirius.Utils.is_function(b.log_to))throw Error("'log_to' argument must be a function");b=b.log_to}else b=a.Default.default_log_function;this.log_function=b;return this._is_initialized=!0},is_valid_level:function(b){return 0!==a.Levels.filter(function(a){return a.get_value()===b}).length},_get_logger_from_input:function(b){var c;return null!=b&&Sirius.Utils.is_string(b)?(c=a.Levels.filter(function(a){return a.get_value()===b.toLowerCase()}))&&0===c.length?a.Debug:c[0]:a.Debug}};
return a}.call(this);Sirius.Internal={DefaultProperty:"text",Errors:"errors"};var lib$sirius$classdecl$var1=function(a){this.value=a;this.fn=function(){}};lib$sirius$classdecl$var1.prototype.and_then=function(a){return null!=this.value?a(this.value):this.fn=a};lib$sirius$classdecl$var1.prototype.set_value=function(a){this.value=a;return this.fn(a)};Sirius.Promise=lib$sirius$classdecl$var1;var lib$sirius$classdecl$var2=function(){};
lib$sirius$classdecl$var2.is_function=function(a){return"[object Function]"===Object.prototype.toString.call(a)};lib$sirius$classdecl$var2.is_string=function(a){return"[object String]"===Object.prototype.toString.call(a)};lib$sirius$classdecl$var2.is_array=function(a){return"[object Array]"===Object.prototype.toString.call(a)};lib$sirius$classdecl$var2.is_object=function(a){return null!==a&&"object"===typeof a};lib$sirius$classdecl$var2.camelize=function(a){return a.charAt(0).toUpperCase()+a.slice(1)};
lib$sirius$classdecl$var2.underscore=function(a){return a.replace(/([A-Z])/g,"_$1").replace(/^_/,"").toLowerCase()};lib$sirius$classdecl$var2.ie_version=function(){var a=window.navigator.userAgent;var b=a.indexOf("MSIE ");var c=a.indexOf("Trident/");return 0<b?parseInt(a.substring(b+5,a.indexOf(".",b)),10):0<c?(b=a.indexOf("rv:"),parseInt(a.substring(b+3,a.indexOf(".",b)),10)):0};
lib$sirius$classdecl$var2.guid=function(){var a=function(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)};return""+a()+a()+"-"+a()+"-"+a()+"-"+a()+"-"+a()+a()+a()};lib$sirius$classdecl$var2.is_ie9=function(){return 9===this.ie_version()};lib$sirius$classdecl$var2.fn_name=function(a){if(this.is_function(a))return a.toString().match(/function ([^\(]+)/)[1];throw Error("Need function, given "+typeof a);};Sirius.Utils=lib$sirius$classdecl$var2;
var lib$sirius$classdecl$var3=function(a){this.setup=a};lib$sirius$classdecl$var3.prototype.hash=function(){return window.location.hash};lib$sirius$classdecl$var3.prototype.current=function(){return window.location.hash};lib$sirius$classdecl$var3.prototype.origin=function(){return window.location.origin};lib$sirius$classdecl$var3.prototype.pathname=function(){var a=window.location.pathname;""===a&&(a="/");return a};
lib$sirius$classdecl$var3.prototype.write=function(a,b,c){return this.setup.has_push_state_support?history.pushState(a,b,c):history.replaceState(a,b,c)};Sirius.Internal.HistoryJournal=lib$sirius$classdecl$var3;
Sirius.redirect=function(a){var b=Sirius.Application;b.get_logger("Redirect").info("Redirect to "+a);b.use_hash_routing_for_old_browsers&&!b.push_state_support&&(a=0===a.indexOf("#")?a:0===a.indexOf("/")?"#"+a:"#/"+a);if(0===a.indexOf("#")){if(b.push_state_support)return location.replace(a)}else if(b.push_state_support)return Sirius.Internal.RouteSystem.dispatch.call(null,{type:"redirect",target:{href:a}})};var lib$sirius$classdecl$var4=function(a,b){this.is_matched=a;this.args=b};
lib$sirius$classdecl$var4.prototype.with_args=function(a){this.args=a;return this};lib$sirius$classdecl$var4.prototype.get_args=function(){return this.args||[]};lib$sirius$classdecl$var4.prototype.is_success=function(){return this.is_matched};lib$sirius$classdecl$var4.prototype.success=function(){this.is_matched=!0;return this};lib$sirius$classdecl$var4.prototype.fail=function(){this.is_matched=!1;return this};Sirius.Internal.RouteMatchResult=lib$sirius$classdecl$var4;
var lib$sirius$classdecl$var5=function(a){this.original=a;this.is_end=!0;this.start=null;this.parts=[];a=a.replace(/\/$/,"").split("/");""===a[0]&&(a[0]="#");"*"===a[a.length-1]&&(this.is_end=!1);this.parts=a.slice(0);this.logger=Sirius.Application.get_logger("Sirius.Internal.RoutePart#"+this.original)};lib$sirius$classdecl$var5._is_named_part=function(a){return 0===a.indexOf(":")};lib$sirius$classdecl$var5._is_regexp_part=function(a){return 0===a.indexOf("[")};
lib$sirius$classdecl$var5._is_end_part=function(a){return 0===a.indexOf("*")};
lib$sirius$classdecl$var5.prototype.match=function(a){this.logger.debug("try to match: '"+a+"'");var b=new Sirius.Internal.RouteMatchResult(!1,[]);var c=a.replace(/\/$/,"").split("/");""===c[0]&&(c[0]="#");if(this.is_end&&c.length!==this.parts.length||1<this.parts.length&&c.length<this.parts.length)return b.fail();var d=-1;for(a=[];10>d;){d++;var e=$jscomp.makeIterator([this.parts[d],c[d]]);var f=e.next().value;e=e.next().value;if(!f||!e)break;if(Sirius.Internal.RoutePart._is_named_part(f))a.push(c[d]);
else if(Sirius.Internal.RoutePart._is_regexp_part(f)){f=new RegExp("^"+f+"$");if(!f.test(e))return b.fail();a.push(f.exec(e)[0])}else{if(Sirius.Internal.RoutePart._is_end_part(f)){a=a.concat(c.slice(d));break}if(f!==e)return b.fail()}}return b.with_args(a).success()};Sirius.Internal.RoutePart=lib$sirius$classdecl$var5;
var lib$sirius$classdecl$var6=function(a,b){b=void 0===b?function(a){return a}:b;this.logger=Sirius.Application.get_logger(this.constructor.name);var c;if(!(c=a.controller))throw Error("Params must contain a Controller definition");var d=a.action;if(Sirius.Utils.is_string(d))var e=c[d];else if(Sirius.Utils.is_function(d))e=d;else throw b="Action must be a string or a function",this.logger.error(b),Error(b);if(!e)throw b="The action '"+d+"' was not found in the controller",this.logger.error("ControlFlow: "+
b),Error(b);this.action=b(e);b=function(b,e){e=void 0===e?!1:e;var f=a[b];var g=c[b+"_"+d];var l=function(a){return Error("The "+a+" method must be a string or a function")};if(Sirius.Utils.is_string(f)){e=c[f];if(!Sirius.Utils.is_function(e))throw l(Sirius.Utils.camelize(b));return e}if(Sirius.Utils.is_function(f))return f;if(f)throw l(Sirius.Utils.camelize(b));if(g){if(!Sirius.Utils.is_function(g))throw l(Sirius.Utils.camelize(b));return g}return e?null:function(){}};this.before=b("before");this.after=
b("after");this.guard=b("guard",!0);this.data=a.data||[];this.controller=c};lib$sirius$classdecl$var6.prototype.handle_event=function(a,b){for(var c=[],d=1;d<arguments.length;++d)c[d-1]=arguments[d];this.logger.debug("Start event processing");return a?(d=Sirius.Utils.is_array(this.data)?this.data:[this.data],d=Sirius.Application.adapter.get_properties(a,d),d=[].concat([],[a],d),this._call_with([].concat.apply([],[[],d].concat($jscomp.arrayFromIterable(c))))):this._call_with([].concat.apply([],c))};
lib$sirius$classdecl$var6.prototype._call_with=function(a){if(this.guard){if(this.guard.apply(this.controller,a))return this.before.apply(this.controller),this.action.apply(this.controller,a),this.after.apply(this.controller)}else return this.before.apply(this.controller),this.action.apply(this.controller,a),this.after.apply(this.controller)};lib$sirius$classdecl$var6.prototype.tick=function(){this.logger.debug("tick");return this._call_with(null)};Sirius.Internal.ControlFlow=lib$sirius$classdecl$var6;
var lib$sirius$classdecl$var7=function(a){this.is_need_redirect_to_hash=a.old;this.has_push_state_support=a.support;this.is_ignore_not_matched_urls=a.ignore};lib$sirius$classdecl$var7.build=function(a){return new Sirius.Internal.RoutingSetup(a)};Sirius.Internal.RoutingSetup=lib$sirius$classdecl$var7;
Sirius.Internal.RouteSystem={_every:"every",_scheduler:"scheduler",_once:"once",_selector:"a:not([href^='#'])",_is_hash_route:function(a){return 0===a.toString().indexOf("#")},_is_404_route:function(a){return"404"===a.toString()},_is_plain_route:function(a){return 0===a.toString().indexOf("/")},_is_scheduler_command:function(a){return 0===a.lastIndexOf(this._scheduler)||0===a.lastIndexOf(this._once)||0===a.lastIndexOf(this._every)},_is_event_route:function(a){return!this._is_hash_route(a)&&!this._is_404_route(a)&&
!this._is_plain_route(a)&&!this._is_scheduler_command(a)},_get_time_unit:function(a,b){var c;if(c=b.match(/^(\d+)(ms|s|m)/))return a=parseInt(c[1],10),c=c[2]||"s","ms"===c?a:"s"===c?1E3*a:6E4*a;throw Error("Bad time unit: "+b+" in "+a+", available units: 'ms', 's', 'm'");},_get_scheduler_params:function(a){var b=a.split(" ");var c="Define time unit for scheduler, for example: 'every 10s', given: "+a;if(1===b.length)throw Error(c);if(2===b.length)return c=Sirius.Internal.RouteSystem._get_time_unit(a,
b[1]),{delay:null,time:c};if(3===b.length)return c=Sirius.Internal.RouteSystem._get_time_unit(a,b[1]),a=Sirius.Internal.RouteSystem._get_time_unit(a,b[2]),{delay:c,time:a};throw Error(c);},_scheduler_register:function(a,b,c){var d;var e=this._every;var f=this._scheduler;var g=this._get_scheduler_params;var h=[];for(d in a){var k=a[d];this._is_scheduler_command(d)&&h.push(function(a,d){var h=Sirius.Utils.is_function(d)?b(d):function(){return(new Sirius.Internal.ControlFlow(d,b)).tick()};var k=g(a);
c.debug("Define scheduler for '"+a+"' with "+JSON.stringify(k));return 0===a.lastIndexOf(e)||0===a.lastIndexOf(f)?null===k.delay?setInterval(h,k.time):setTimeout(function(){return setInterval(h,k.time)},k.delay):null===k.delay?setTimeout(h,k.time):setTimeout(function(){return setTimeout(h,k.time)},k.delay)}(d,k))}return h},_event_register:function(a,b,c,d){var e;var f=[];for(e in a){var g=a[e];this._is_event_route(e)&&f.push(function(a,e){var f=Sirius.Utils.is_function(e)?b(e):function(a,c){for(var d=
[],f=1;f<arguments.length;++f)d[f-1]=arguments[f];return(new Sirius.Internal.ControlFlow(e,b)).handle_event(a,d)};var g=a.match(/^([a-zA-Z:]+)(\s+)?(.*)?/);a=g[1];g=g[3]||document;c.bind(document,g,a,f);return d.debug("define event route: '"+a+"' for '"+c.as_string(g)+"'")}(e,g))}return f},_get_hash_routes:function(a,b,c){var d=[];for(f in a){var e=a[f];if(this._is_hash_route(f)){c.info("define hash route: '"+f+"' ~> "+e);var f=new Sirius.Internal.RoutePart(f);e=Sirius.Utils.is_function(e)?b(e):new Sirius.Internal.ControlFlow(e,
b);d.push([f,e])}}return d},_get_plain_routes:function(a,b,c){var d=[];for(f in a){var e=a[f];if(this._is_plain_route(f)){c.debug("define route: '"+f+"' ~> "+e);var f=new Sirius.Internal.RoutePart(f);e=Sirius.Utils.is_function(e)?b(e):new Sirius.Internal.ControlFlow(e,b);d.push([f,e])}}return d},_convert_to_hash_routing:function(a,b,c){if(a.is_need_redirect_to_hash&&!a.has_push_state_support){c.info("Convert plain routing into hash routing");var d=[];c={};for(e in b){a=b[e];this._is_hash_route(e)&&
d.push(e);if(this._is_plain_route(e)){var e="#"+e;-1!==d.indexOf(e)&&this.logger.warn("Routes already defined '"+e+"' url")}c[e]=a}b=c}return b},_try_to_call:function(a,b){var c;var d=!1;var e=0;for(c=a.length;e<c;e++){var f=$jscomp.makeIterator(a[e]);var g=f.next().value;f=f.next().value;d||(g=g.match(b),g.is_success()&&(d=!0,f.handle_event?f.handle_event(null,g.get_args()):f.apply(null,g.get_args())))}return d},_handle_404_event:function(a,b,c,d,e,f){f.warn("route '"+b+"' not found. Generate 404 event");
e.fire(document,"application:404",b,c);if(a=a["404"]||a[404])return Sirius.Utils.is_function(a)?d(a)(b):(new Sirius.Internal.ControlFlow(a,d)).handle_event(null,b)},create:function(a,b,c){var d=this;c=void 0===c?function(){}:c;var e;var f=Sirius.Application.get_logger("Sirius.Internal.RouteSystem");var g=new Sirius.Internal.HistoryJournal(b);var h=e=g.hash();return Sirius.Application.get_adapter().and_then(function(k){a=d._convert_to_hash_routing(b,a,f);var l=function(a){var b;var c=Sirius.Application.controller_wrapper;
for(b in c){var d=c[b];this[b]=d}return a};d._event_register(a,l,k,f);d._scheduler_register(a,l,k,f);var m=d._get_hash_routes(a,l,f);var n=d._get_plain_routes(a,l,f);var p=function(a){return a.preventDefault?a.preventDefault():a.returnValue=!1};var q=function(c){e=h;f.debug("start processing route: '"+h+"'");if("hashchange"===c.type){var d=m;h=g.hash();var q=g.origin();g.write({href:h},""+h,q+"/"+h)}else d=n,q=c.target.href,"popstate"!==c.type&&b.has_push_state_support&&g.write({href:q},""+q,q),h=
q=g.pathname();Sirius.Internal.RouteSystem._try_to_call(d,h)?(p(c),f.debug("Url changed to: "+h),k.fire(document,"application:urlchange",h,e)):b.is_ignore_not_matched_urls?f.debug("the URL was not matched: '"+h+"'"):(Sirius.Internal.RouteSystem._handle_404_event(a,h,e,l,k,f),p(c))};d.dispatch=q;0!==n.length&&k.bind(document,d._selector,"click",q);window.onhashchange=q;b.has_push_state_support&&k.bind(window,null,"popstate",function(a){if(history&&null!=history.state&&void 0!==history.state.href&&
0!==history.state.href.indexOf("#"))return q(a)});return c()})}};
Sirius.Application={enable_logging:Sirius.Logger.Default.enable_logging,minimum_log_level:Sirius.Logger.Default.minimum_log_level,log_to:Sirius.Logger.Default.default_log_function,adapter:null,route:{},start:!1,controller_wrapper:{redirect:Sirius.redirect},use_hash_routing_for_old_browsers:!0,ignore_not_matched_urls:!0,_wait:[],get_logger:function(a){return Sirius.Logger.build(a)},get_adapter:function(){if(null==this.adapter){var a=new Sirius.Promise;this._wait.push(a);return a}return new Sirius.Promise(this.adapter)},
run:function(a){a=void 0===a?{}:a;this._initialize(a)},_initialize:function(a){var b=this,c;Sirius.Logger.Configuration.configure(a);var d=new Sirius.Logger("Sirius.Application");var e=function(b,c){return null!=a[b]?a[b]:c};this.adapter=a.adapter||new VanillaJsAdapter;this.route=a.route||this.route;this.ignore_not_matched_urls=e("ignore_not_matched_urls",this.ignore_not_matched_urls);this.start=a.start||this.start;var f=a.controller_wrapper||{};for(c in f){var g=f[c];this.controller_wrapper[c]=g}this.hash_always_on_top=
e("hash_always_on_top",this.hash_always_on_top);this.use_hash_routing_for_old_browsers=e("use_hash_routing_for_old_browsers",this.use_hash_routing_for_old_browsers);d.info("Logger enabled? "+Sirius.Logger.Configuration.enable_logging);d.info("Minimum log level: "+Sirius.Logger.Configuration.minimum_log_level.get_value());d.info("Adapter: "+this.adapter._adapter_name);d.info("Use hash routing for old browsers: "+this.use_hash_routing_for_old_browsers);d.info("Current browser: "+navigator.userAgent);
d.info("Ignore not matched urls: "+this.ignore_not_matched_urls);this.push_state_support=history.pushState;d.info("History pushState support: !!"+this.push_state_support);!this.push_state_support&&this.use_hash_routing_for_old_browsers&&d.warn("You browser does not support pushState, and you disabled hash routing for old browser");e=Sirius.Internal.RoutingSetup.build({old:this.use_hash_routing_for_old_browsers,support:this.push_state_support,ignore:this.ignore_not_matched_urls});Sirius.Internal.RouteSystem.create(this.route,
e,function(){var a;var c=b._wait;var d=0;for(a=c.length;d<a;d++){var e=c[d];e.set_value(b.adapter)}return b.adapter.fire(document,"application:run",new Date)});if(this.start)return Sirius.redirect(this.start)}};Sirius.Validator=function(){var a=function(){this.logger=Sirius.Application.get_logger(this.constructor.name);this.msg=null};a.prototype.error_message=function(){return this.msg};a.ValidateWith="validate_with";return a}.call(this);
var lib$sirius$classdecl$var8=function(){return Sirius.Validator.apply(this,arguments)||this};$jscomp.inherits(lib$sirius$classdecl$var8,Sirius.Validator);
lib$sirius$classdecl$var8.prototype.validate=function(a,b){this.logger.info("LengthValidator: start validate '"+a+"'");if(null!=a){var c=b.max||Number.POSITIVE_INFINITY;var d=b.min||Number.NEGATIVE_INFINITY;b=b.length;a=a.length;if(b){if(a===b)return!0;this.msg="Required length: "+b+", given: "+a;return!1}if(a>=d&&a<=c)return!0;this.msg="Required length in range [0.."+c+"], given: "+a;return!1}this.msg="Given null for LengthValidator";return!1};Sirius.LengthValidator=lib$sirius$classdecl$var8;
var lib$sirius$classdecl$var9=function(){return Sirius.Validator.apply(this,arguments)||this};$jscomp.inherits(lib$sirius$classdecl$var9,Sirius.Validator);lib$sirius$classdecl$var9.prototype.validate=function(a,b){this.logger.info("ExclusionValidator: start validate '"+a+"'");if(-1===(b.within||[]).indexOf(a))return!0;this.msg="Value "+a+" reserved";return!1};Sirius.ExclusionValidator=lib$sirius$classdecl$var9;
var lib$sirius$classdecl$var10=function(){return Sirius.Validator.apply(this,arguments)||this};$jscomp.inherits(lib$sirius$classdecl$var10,Sirius.Validator);lib$sirius$classdecl$var10.prototype.validate=function(a,b){this.logger.info("InclusionValidator: start validate '"+a+"'");b=b.within||[];if(-1<b.indexOf(a))return!0;this.msg="Value "+a+" should be in range "+b;return!1};Sirius.InclusionValidator=lib$sirius$classdecl$var10;
var lib$sirius$classdecl$var11=function(){return Sirius.Validator.apply(this,arguments)||this};$jscomp.inherits(lib$sirius$classdecl$var11,Sirius.Validator);lib$sirius$classdecl$var11.prototype.validate=function(a,b){this.logger.info("FormatValidator: start validate '"+a+"'");if(!(b=b["with"]))throw Error("format attribute required");if(null!=a){if(b.test(a))return!0;this.msg="Value "+a+" not in current format";return!1}this.msg="Given null for Format";return!1};Sirius.FormatValidator=lib$sirius$classdecl$var11;
var lib$sirius$classdecl$var12=function(){return Sirius.Validator.apply(this,arguments)||this};$jscomp.inherits(lib$sirius$classdecl$var12,Sirius.Validator);lib$sirius$classdecl$var12.prototype.validate=function(a,b){b=void 0===b?{}:b;this.logger.info("NumericalityValidator: start validate '"+a+"'");if(b.only_integers){if(/^\d+$/.test(a))return!0;this.msg="Only allows integer numbers";return!1}if(/^\d+(?:\.\d{1,})?$/.test(a))return!0;this.msg="Only allows numbers";return!1};
Sirius.NumericalityValidator=lib$sirius$classdecl$var12;var lib$sirius$classdecl$var13=function(){return Sirius.Validator.apply(this,arguments)||this};$jscomp.inherits(lib$sirius$classdecl$var13,Sirius.Validator);lib$sirius$classdecl$var13.prototype.validate=function(a,b){this.logger.info("PresenceValidator: start validate '"+a+"'");if(a)return!0;this.msg="Value required";return!1};Sirius.PresenceValidator=lib$sirius$classdecl$var13;var lib$sirius$classdecl$var14=function(){};
Sirius.Internal.AbstractHandler=lib$sirius$classdecl$var14;var lib$sirius$classdecl$var15=function(a,b){Sirius.Internal.AbstractHandler.call(this);this.guid=a;this.observer=b};$jscomp.inherits(lib$sirius$classdecl$var15,Sirius.Internal.AbstractHandler);Sirius.Internal.ObserverHandler=lib$sirius$classdecl$var15;var lib$sirius$classdecl$var16=function(a,b,c,d){Sirius.Internal.AbstractHandler.call(this);this.guid=a;this.from=b;this.event=c;this.fun=d};$jscomp.inherits(lib$sirius$classdecl$var16,Sirius.Internal.AbstractHandler);
lib$sirius$classdecl$var16.prototype.with_event=function(a){this.event=a;return this};lib$sirius$classdecl$var16.build=function(a,b,c,d){this.guid=a;this.from=b;this.event=c;this.fun=d;return new Sirius.Internal.EventHandler(this.guid,this.from,this.event,this.fun)};Sirius.Internal.EventHandler=lib$sirius$classdecl$var16;
Sirius.Internal.CacheObserverHandlers={_handlers:[],add:function(a){return this._handlers.push(a)},remove_where:function(a){var b=this._handlers.filter(function(b){return b.guid===a});this._handlers=this._handlers.filter(function(b){return b.guid!==a});return b}};var lib$sirius$classdecl$var17=function(){};
lib$sirius$classdecl$var17.build=function(a){var b=a.from;var c=a.element;return null!=a.state?new Sirius.StateChanges(a.state,b,c):null!=a.attribute?new Sirius.AttributeChanges(a.text,a.attribute,b,c):new Sirius.TextChanges(a.text,b,c)};Sirius.AbstractChangesResult=lib$sirius$classdecl$var17;var lib$sirius$classdecl$var18=function(a,b,c){Sirius.AbstractChangesResult.call(this);this.text=a;this.from=b;this.target=c};$jscomp.inherits(lib$sirius$classdecl$var18,Sirius.AbstractChangesResult);
lib$sirius$classdecl$var18.build=Sirius.AbstractChangesResult.build;Sirius.TextChanges=lib$sirius$classdecl$var18;var lib$sirius$classdecl$var19=function(a,b,c,d){Sirius.AbstractChangesResult.call(this);this.text=a;this.attribute=b;this.from=c;this.target=d};$jscomp.inherits(lib$sirius$classdecl$var19,Sirius.AbstractChangesResult);lib$sirius$classdecl$var19.build=Sirius.AbstractChangesResult.build;Sirius.AttributeChanges=lib$sirius$classdecl$var19;
var lib$sirius$classdecl$var20=function(a,b,c){Sirius.AbstractChangesResult.call(this);this.state=a;this.from=b;this.target=c};$jscomp.inherits(lib$sirius$classdecl$var20,Sirius.AbstractChangesResult);lib$sirius$classdecl$var20.build=Sirius.AbstractChangesResult.build;Sirius.StateChanges=lib$sirius$classdecl$var20;
Sirius.Internal.Observer=function(){var a=function(a,b,c){c=void 0===c?function(){}:c;this._create=this._create.bind(this);this.from_element=a;this.watch_for=b;this.clb=c;this.guid="Observer#"+Sirius.Utils.guid();this.logger=Sirius.Application.get_logger(this.constructor.name);Sirius.Application.get_adapter().and_then(this._create)};a.is_text_event=function(a){return-1!==this.TextEvents.indexOf(a.type)};a.is_focus_event=function(a){return-1!==[this.Ev.focusin,this.Ev.focusout].indexOf(a.type)};a.prototype._create=
function(a){var f=this.logger;var h=this.clb;var k=this.from_element;var l=null;var m=this.watch_for;var n=this.guid;var p=a.get_attr(k,"tagName");var q=a.get_attr(k,"type");f.debug("Create binding for "+k);var r=Sirius.Internal.Observer;var t=function(b){f.debug("Handler Function: given "+b.type+" event");var c={text:null,attribute:null,from:k,element:b.target};if(!r.is_focus_event(b)){var d=a.text(k);if(-1===[r.Ev.input,r.Ev.selectionchange].indexOf(b.type)||d!==l){r.is_text_event(b)&&(l=c.text=
d);b.type===r.Ev.change&&(c.state=a.get_attr(k,"checked"));if("attributes"===b.type){d=b.attributeName;var e=b.oldValue||[];var g=a.get_attr(k,d);c.text=g;c.attribute=d;c.previous=e}b.type===r.Ev.DOMAttrModified&&(d=b.originalEvent.attrName,e=b.originalEvent.prevValue,g=a.get_attr(k,d),c.text=g,c.attribute=d,c.previous=e);return h(Sirius.AbstractChangesResult.build(c))}}};var u=Sirius.Internal.EventHandler.build(n,k,null,t);if(m===Sirius.Internal.DefaultProperty)if(-1!==c.indexOf(p)){f.debug("It is not "+
c);if(-1!==d.indexOf(q)||p===e)return f.debug("Get "+q+" & "+p+" element for bool elements"),a.bind(document,k,r.Ev.change,t),Sirius.Internal.CacheObserverHandlers.add(u.with_event(r.Ev.change));l=a.text(k);a.bind(document,k,r.Ev.input,t);Sirius.Internal.CacheObserverHandlers.add(u.with_event(r.Ev.input));if(Sirius.Utils.is_ie9())return f.warn("Hook for work with IE9 browser"),a.bind(document,k,r.Ev.selectionchange,t),Sirius.Internal.CacheObserverHandlers.add(u.with_event(r.Ev.selectionchange))}else return f.warn("Seems you try to bind for "+
p+" of "+q+" for 'text' which is not supported");else{if(b)return f.debug("MutationObserver support"),q=new b(function(a){return a.forEach(t)}),u={childList:!0,attributes:!0,characterData:!0,attributeOldValue:!0,characterDataOldValue:!0,subtree:!1},p=a.get(k),q.observe(p,u),Sirius.Internal.CacheObserverHandlers.add(new Sirius.Internal.ObserverHandler(n,q));f.warn("MutationObserver not supported");f.warn("Use Deprecated events for observe");a.bind(document,k,r.Ev.DOMNodeInserted,t);a.bind(document,
k,r.Ev.DOMAttrModified,t);Sirius.Internal.CacheObserverHandlers.add(u.with_event(r.Ev.DOMNodeInserted));return Sirius.Internal.CacheObserverHandlers.add(u.with_event(r.Ev.DOMAttrModified))}};a.prototype.stop=function(){var a=Sirius.Internal.CacheObserverHandlers.remove_where(this.guid);var b=this.logger;return Sirius.Application.get_adapter().and_then(function(c){var d;var e=[];var f=0;for(d=a.length;f<d;f++){var g=a[f];g instanceof Sirius.Internal.ObserverHandler?(b.debug("Stop observer: "+g.guid),
e.push(g.observer.disconnect())):(b.debug("Stop event observer: "+g.guid),e.push(c.off(g.from,g.event,g.fun)))}return e})};var b=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver||null;var c=["INPUT","TEXTAREA","SELECT"];var d=["checkbox","radio"];var e="OPTION";a.Ev={input:"input",selectionchange:"selectionchange",childList:"childList",change:"change",DOMNodeInserted:"DOMNodeInserted",focusout:"focusout",focusin:"focusin",DOMAttrModified:"DOMAttrModified"};a.TextEvents=
[a.Ev.input,a.Ev.childList,a.Ev.DOMNodeInserted,a.Ev.selectionchange];return a}.call(this);
Sirius.View=function(){var a=function(a,b){var c=this;b=void 0===b?function(a){return a}:b;this.element=a;this.clb=b;var d=this.element;var e=this.clb;a=Sirius.View._Cache.filter(function(a){return a.element===d&&""+a.clb===""+e});if(0!==a.length)return a[0];this._listeners=[];this._cache_event_handlers=[];this.logger=Sirius.Application.get_logger("Sirius.View[{"+this.get_element()+"]");this._result_fn=function(a){for(var b=[],c=0;c<arguments.length;++c)b[c-0]=arguments[c];return e.apply.apply(e,
[null].concat($jscomp.arrayFromIterable(b)))};this.logger.debug("Create a new View for "+this.element);var k=this.constructor._Strategies;a=0;for(b=k.length;a<b;a++){var l=k[a];(function(a){var b=$jscomp.makeIterator(a);a=b.next().value;var e=b.next().value;var f=b.next().value;c.constructor._Strategies_Is_Logged||c.logger.debug("Define '"+a+"' strategy");c.constructor._Strategies_Is_Logged=!0;return c[a]=function(a){a=void 0===a?"text":a;var b=c._result;d=c.element;c.logger.debug("Start processing strategy for the "+
d);return Sirius.Application.get_adapter().and_then(function(c){var g="text"===a?c.text(d):c.get_attr(d,a);g=e(g,b);return f(c,d,g,a)})}})(l)}Sirius.View._Cache.push(this);return this};a.prototype.name=function(){return"View"};a.prototype.get_element=function(){return this.element};a.prototype._register_state_listener=function(a){this.logger.debug("Register new listener '"+a.name+"'");return this._listeners.push(a)};a.prototype._unregister_state_listener=function(a){this.logger.debug("Unregister listener '"+
a+"'");var b=this._listeners.filter(function(b){return b.name===a});this._listeners=this._listeners.filter(function(b){return b.name!==a});return b};a.prototype.render=function(a){for(var b=[],c=0;c<arguments.length;++c)b[c-0]=arguments[c];this.logger.debug("Call render for "+b);this._result=this._result_fn(b);return this};a.prototype.zoom=function(a){a=a===this.element?this:new Sirius.View(this.element+" "+a);a._result=this._result;return a};a.prototype.on=function(a,b,f,g){for(var d=[],e=3;e<arguments.length;++e)d[e-
3]=arguments[e];a=a===this.element?a:this.element+" "+a;if(Sirius.Utils.is_string(f))var l=0;else if(Sirius.Utils.is_function(f))l=1;else throw Error("View: 'custom_event_name' must be string or function, '"+typeof f+"' given");var m=new c(a,b,f);e=this._cache_event_handlers.filter(function(a){return a.eq(m)});if(0===e.length)if(this.logger.info("Bind event for "+a+", event name: "+b+", will be called : "+f),0===l){var n=function(a){return Sirius.Application.get_adapter().and_then(function(b){return b.fire.call.apply(b.fire,
[null,document,f,a].concat($jscomp.arrayFromIterable(d)))})};Sirius.Application.get_adapter().and_then(function(c){return c.bind(document,a,b,n)});e=new c(a,b,n);this._cache_event_handlers.push(e)}else Sirius.Application.get_adapter().and_then(function(c){return c.bind(document,a,b,f)}),this._cache_event_handlers.push(m);else{var p=e.shift();e=this._cache_event_handlers.indexOf(p);-1<e&&this._cache_event_handlers.splice(e,1);this._cache_event_handlers.push(m);Sirius.Application.get_adapter().and_then(function(c){c.off(a,
b,p.custom_event_name);p=null;return c.bind(document,a,b,f)})}};a.prototype.for_me=function(a,b,c){for(var d=[],e=2;e<arguments.length;++e)d[e-2]=arguments[e];return this.on.apply(this,[this.get_element(),a,b].concat($jscomp.arrayFromIterable(d)))};a.prototype.get_attr=function(a){var b=this.get_element();return Sirius.Application.get_adapter().and_then(function(c){return c.get_attr(b,a)})};a.is_valid_strategy=function(a){return 0!==this._Strategies.filter(function(b){return b[0]===a}).length};a.register_strategy=
function(a,b){b=void 0===b?{}:b;var c=Sirius.Application.get_logger("Sirius.View.Static");c.info("View: Register new Strategy "+a);var d=b.transform;b=b.render;if(!Sirius.Utils.is_function(d))throw a="Strategy 'transform' must be a function, but "+typeof d+" given",c.error("View: "+a),Error(a);if(!Sirius.Utils.is_function(b))throw a="Strategy 'render' must be a function, but "+typeof b+" given",c.error("View: "+a),Error(a);if(!Sirius.Utils.is_string(a))throw a="Strategy 'name' must be a string, but "+
typeof a+" given",c.error("View: "+a),Error(a);this._Strategies.push([a,d,b]);return null};a._run_view_strategy_registration=function(){Sirius.View.register_strategy("swap",{transform:function(a,b){return""+b},render:function(a,b,c,g){return"text"===g?a.swap(b,c):"checked"===g?(c=Sirius.Utils.is_string(c)?"true"===c?!0:!1:!!c,a.set_attr(b,"checked",c)):a.set_attr(b,g,c)}});Sirius.View.register_strategy("append",{transform:function(a,b){return b},render:function(a,b,c,g){var d=a.get_attr(b,"tagName");
if("INPUT"===d||"TEXTAREA"===d||"SELECT"===d)throw Error("'append' strategy does not work for `input` or `textarea` or `select` elements");if("text"===g)return a.append(b,c);throw Error("Strategy 'append' works only for 'text' content, your call with attribute:'"+g+"'");}});Sirius.View.register_strategy("prepend",{transform:function(a,b){return b},render:function(a,b,c,g){var d=a.get_attr(b,"tagName");if("INPUT"===d||"TEXTAREA"===d||"SELECT"===d)throw Error("'prepend' strategy does not work for `input` or `textarea` or `select` elements");
if("text"===g)return a.prepend(b,c);throw Error("Strategy 'prepend' works only for 'text' content, your call with attribute:'"+g+"'");}});return Sirius.View.register_strategy("clear",{transform:function(a,b){return""},render:function(a,b,c,g){return a.clear(b)}})};a._Strategies=[];a._Strategies_Is_Logged=!1;a._Cache=[];var b=function(a,b,c){this.selector=a;this.event_name=b;this.custom_event_name=c};b.prototype.eq=function(a){return this.selector===a.selector&&this.event_name===a.event_name&&this.custom_event_name.toString===
a.custom_event_name.toString};var c=b;return a}.call(this);Sirius.View._run_view_strategy_registration();var lib$sirius$classdecl$var22=function(a,b,c){this.main=a;this.fields=b;this.fn=void 0===c?null:c;this._count=this.fields.length;this._values=[]};lib$sirius$classdecl$var22.prototype.get_fields=function(){return this.fields};
lib$sirius$classdecl$var22.prototype.complete=function(a,b){var c={};c[a]=b;return-1===this._values.map(function(a){return Object.keys(a)[0]}).indexOf(a)?(this._values.push(c),this.is_full()?this._result():null):null};lib$sirius$classdecl$var22.prototype.field_name=function(){return this.main};lib$sirius$classdecl$var22.prototype.remove=function(a){return delete this._values[a]};
lib$sirius$classdecl$var22.prototype._result=function(){var a=this._values;var b=this.fields.map(function(b){return a.filter(function(a){return a[b]})[0][b]});return null===this.fn?b.join(" "):this.fn.apply(null,b)};lib$sirius$classdecl$var22.prototype.is_full=function(){return this._values.length===this._count};ComputedField=lib$sirius$classdecl$var22;
Sirius.BaseModel=function(){var a=function(a){a=void 0===a?{}:a;var b,d,e,f,g;(b=this.constructor.prototype)._cmp||(b._cmp=[]);(d=this.constructor.prototype)._cmp_fields||(d._cmp_fields=[]);this._listeners=[];this.logger=Sirius.Application.get_logger(this.constructor.name);this.errors={};this.attributes=this.normalize_attrs();d=this.constructor.name;this.errors={};this._is_valid_attr={};var h=this.attrs();this.binding={};var k=0;for(f=h.length;k<f;k++)if(b=h[k],this.constructor._attributes_are_logged||
this.logger.info("define '"+JSON.stringify(b)+"' attribute for '"+d+"'"),this.constructor._attributes_are_logged=!0,Sirius.Utils.is_object(b)){var l=Object.keys(b);var m=l[0];if(0===l.length)throw this.logger.error("@attrs must be defined as: '@attrs:['id', {'k':'v'}]'"),Error("@attrs must be defined as: '@attrs:['id', {'k':'v'}]'");this["_"+m]=b[m];this._gen_method_name_for_attribute(m)}else this._gen_method_name_for_attribute(b),this["_"+b]=null;var n=this.constructor.skip;d=this.attributes;f=Object.keys(a);
l=0;for(h=f.length;l<h;l++)b=f[l],-1===d.indexOf(b)&&n||(this._attribute_present(b),k=this["_"+b],this["_"+b]=a[b],this._call_callbacks(b,a[b],k));l=this.guid_for();d=0;for(b=l.length;d<b;d++)a=l[d],this.logger.debug("Generate guid for '"+this._klass_name()+"."+a+"'"),this.set(a,this._generate_guid());this._registered_validators=this.constructor._Validators;this._registered_validators_keys=this._registered_validators.map(function(a){return a[0]});this._model_validators=this.validators();this._applicable_validators=
{};a=this._model_validators;for(m in a)for(g in b=a[m],this.errors[m]={},this._is_valid_attr[m]=!1,b){d=b[g];if(-1===this._registered_validators_keys.indexOf(g)&&g!==Sirius.Validator.ValidateWith)throw Error("Unregistered validator: '"+g+"'");if(g===Sirius.Validator.ValidateWith&&!Sirius.Utils.is_function(d))throw Error("Validator for attribute: '"+m+"."+g+"' should be a function, "+typeof d+" given");l=$jscomp.makeIterator(g===Sirius.Validator.ValidateWith?(e=new Sirius.Validator,e.validate=d,e.msg=
null,[Sirius.Validator.ValidateWith,e]):(e=this._registered_validators.filter(function(a){return a[0]===g})[0][1],[g,new e]));d=l.next().value;h=l.next().value;l=this._applicable_validators[m]||{};l[d]=h;this._applicable_validators[m]=l}this._gen_binding_names();this.after_create()};a.comp=function(a){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=this,f,g,h,k;(f=this.prototype)._cmp||(f._cmp=[]);(g=this.prototype)._cmp_fields||(g._cmp_fields=[]);(h=this.prototype)._cmp_refs||(h._cmp_refs=
{});if(0===b.length)throw Error("Computed fields are empty");if(2===b.length)throw Error('Define compute field like: \'@comp("default_computed_field", "first_name", "last_name")\'');var l=b[0];d=b.length;f=$jscomp.makeIterator(Sirius.Utils.is_function(b[d-1])?(k=b[d-1],[b.slice(1,d-1),b.slice(1,d-1),k]):[b.slice(1),b.slice(1),null]);b=f.next().value;d=f.next().value;k=f.next().value;f=[l].concat(b);if(f.filter(function(a,b,c){return c.indexOf(a)===b}).length!==f.length)throw Error("Seems your calculated fields are not unique: ["+
f+"]");h=[];var m=this.attrs;f=0;for(g=m.length;f<g;f++){var n=m[f];n=Sirius.Utils.is_object(n)?Object.keys(n)[0]:n;h.push(n)}var p=h.concat(this.prototype._cmp_fields);b.forEach(function(a){if(-1===p.indexOf(a))throw Error("Field '"+a+"' was not found, for '"+l+"'");});if(0<this.prototype._cmp_fields.length&&(n=b.filter(function(a){return e.prototype._cmp_refs[a]&&-1!==e.prototype._cmp_refs[a].indexOf(l)}),0<n.length))throw Error("Cyclic references were detected in '"+l+"' field");Sirius.Application.get_logger("Sirius.BaseModel").info("Define compute field '"+
l+"' <- '["+b+"]'");this.prototype._cmp_refs[l]=b;this.prototype._cmp_fields.push(l);return this.prototype._cmp.push(new ComputedField(l,d,k))};a.prototype.attrs=function(){return(this.constructor.attrs||[]).concat(this.constructor.prototype._cmp_fields)};a.prototype.normal_name=function(){return Sirius.Utils.underscore(this.constructor.name)};a.prototype._klass_name=function(){return this.constructor.name};a.prototype.validators=function(){return this.constructor.validate||{}};a.prototype.guid_for=
function(){var a;if(a=this.constructor.guid_for){if(Sirius.Utils.is_string(a))return[a];if(Sirius.Utils.is_array(a))return a;throw Error("'@guid_for' must be array of string, but "+typeof a+" given");}return[]};a.prototype._compute=function(a,c){var b=this;return this.constructor.prototype._cmp.forEach(function(d){if(-1!==d.get_fields().indexOf(a)){var e=d.complete(a,c);if(d.is_full())return b._set(d.field_name(),e)}})};a.prototype.normalize_attrs=function(){var a;var c=this.attrs();var d=[];var e=
0;for(a=c.length;e<a;e++){var f=c[e];d.push(function(a){return Sirius.Utils.is_object(a)?Object.keys(a)[0]:a}(f))}return d};a.prototype._gen_method_name_for_attribute=function(a){var b=this;var d=Sirius.Utils.underscore(a);if(-1!==Object.keys(this).indexOf(d))throw Error("Method '"+d+"' already exist");return this[d]=function(c){return null!=c?b.set(a,c):b.get(a)}};a.prototype._gen_binding_names=function(){var a,c,d;var e={};var f=this.get_attributes();var g=0;for(c=f.length;g<c;g++){var h=f[g];if(h===
Sirius.Internal.Errors)throw Error("'errors' name is reserved");e[h]=h}if(0!==Object.keys(this._applicable_validators).length){h={};g=this._applicable_validators;for(a in g){f=g[a];c={};var k=Object.keys(f);f=0;for(d=k.length;f<d;f++){var l=k[f];if("all"===l)throw Error("Name 'all' for validators is reserved");c[l]=Sirius.Internal.Errors+"."+a+"."+l}c.all=Sirius.Internal.Errors+"."+a+".all";h[a]=c}h.all=Sirius.Internal.Errors+".all";e[Sirius.Internal.Errors]=h}return this.binding=e};a.prototype.get_binding=
function(){return this.binding};a.prototype._generate_guid=function(){return Sirius.Utils.guid()};a.prototype.get_attributes=function(){return this.attributes};a.prototype._is_computed_attribute=function(a){return-1!==this.constructor.prototype._cmp_fields.indexOf(a)?!0:!1};a.prototype._attribute_present=function(a){if(-1===this.attributes.indexOf(a))throw Error("Attribute '"+a+"' not found for "+this._klass_name()+" model");};a.prototype._call_callbacks=function(a,c,d){var b;var f=this._listeners;
var g=0;for(b=f.length;g<b;g++){var h=f[g];h.handler.apply(null,[a,c])}return this.after_update(a,c,d)};a.prototype._call_callbacks_for_errors=function(a,c,d){var b;a=Sirius.Internal.Errors+"."+a+"."+c;var f=this._listeners;var g=[];var h=0;for(b=f.length;h<b;h++)c=f[h],g.push(c.handler.apply(null,[a,d]));return g};a.prototype.set=function(a,c){if(this._is_computed_attribute(a))throw Error("Impossible set computed attribute '"+a+"' in '"+this._klass_name()+"'");return this._set(a,c)};a.prototype._set=
function(a,c,d){d=void 0===d?!1:d;this._attribute_present(a);var b=this["_"+a];this["_"+a]=c;this.validate(a);return d||this.is_valid(a)?(this.logger.debug("set: '"+c+"' to '"+a+"'"),this._compute(a,c),this._call_callbacks(a,c,b)):this["_"+a]=b};a.prototype.get=function(a){this._attribute_present(a);return this["_"+a]};a.prototype.reset=function(a){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e;var f=null!=b&&0!==b.length?b:this.attrs();this.logger.debug("Reset attributes: '"+f.join(",")+
"' for "+this._klass_name());d=0;for(e=f.length;d<e;d++)b=f[d],this._set(b,null,!0),null!=this.errors[b]&&(this.errors[b]={})};a.prototype._is_valid_validator=function(a){a=a.split(".");if(2===a.length){var b=$jscomp.makeIterator(a);a=b.next().value;b=b.next().value;return null!=this._applicable_validators[a]&&null!=this._applicable_validators[a][b]}return!1};a.prototype.is_valid=function(a){var b=this;a=void 0===a?null:a;return null!=a?null!=this._is_valid_attr[a]?this._is_valid_attr[a]:!0:0===Object.keys(this._is_valid_attr).filter(function(a){return!b._is_valid_attr[a]}).length};
a.prototype.validate=function(a){a=void 0===a?null:a;var b,d;var e=this._klass_name();var f=this.logger;var g=Object.keys(this._model_validators||{});var h=null!=a?g.filter(function(b){return b===a}):g;var k=0;for(b=h.length;k<b;k++){var l=h[k];var m=this.get(l);g=this._model_validators[l];for(d in g){var n=g[d];var p=this._applicable_validators[l][d];n=p.validate(m,n);f.debug("Validate: '"+e+"."+l+" = "+m+"' with '"+d+"' validator, valid?: '"+n+"'");p=n?(delete this.errors[l][d],this._is_valid_attr[l]=
!0,""):(this.errors[l][d]=p.error_message(),this._is_valid_attr[l]=!1,p.error_message());this._call_callbacks_for_errors(l,d,p)}}};a.prototype.get_errors=function(a){a=void 0===a?null:a;var b;if(null!=a){this._attribute_present(a);var d=[];a=this.errors[a];for(b in a){var e=a[b];""!==e&&d.push(e)}return d}return this.errors};a.prototype.set_error=function(a,c){a=a.split(".");if(2!==a.length)throw Error("Message must be pass as 'attr.validator' like 'name.length'");var b=$jscomp.makeIterator(a);a=
b.next().value;b=b.next().value;if(null==this._applicable_validators[a][b])throw Error("Unexpected key: '"+b+"' for '"+a+"' attribute");this.errors[a][b]=c;this._is_valid_attr[a]=!1;return this._call_callbacks_for_errors(a,b,c)};a.prototype.save=function(){this.validate();return this.is_valid()?!1:!0};a.prototype.to_json=function(a){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];return JSON.stringify(this.to_object.apply(this,$jscomp.arrayFromIterable(b)))};a.prototype.to_object=function(a){for(var b=
[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e;var f={};var g=this.attributes;var h=0;for(e=g.length;h<e;h++)if(d=g[h],-1===b.indexOf(d)){var k=this.get(d);f[d]=k}return f};a.from_json=function(a){var b;var d=new this;a=JSON.parse(a);var e=[].concat(d.attrs());var f=0;for(b=e.length;f<b;f++){var g=e[f];if("object"===typeof g){var h=Object.keys(g);h=h[0];d.set(h,a[h]||g[h])}else h=a[g],d.set(g,h||d.get(g))}return d};a.prototype.compare=function(a){throw Error("`compare` method must be overridden");
};a.prototype.after_create=function(){};a.prototype.after_update=function(a,c,d){};a.prototype.clone=function(){return this.constructor.from_json(this.to_json())};a.prototype._register_state_listener=function(a){var b;this.logger.debug("Register new listener '"+a.name+"'");this._listeners.push(a);var d=this.get_attributes();var e=[];var f=0;for(b=d.length;f<b;f++){var g=d[f];null!==this["_"+g]?e.push(a.handler.apply(null,[g,this["_"+g]])):e.push(void 0)}return e};a.prototype._unregister_state_listener=
function(a){this.logger.debug("Unregister listener '"+a+"'");this._listeners=this._listeners.filter(function(b){return b.name!==a})};a.register_validator=function(a,c){Sirius.Application.get_logger("Sirius.BaseModel.Static").info("register validator: "+a);this._Validators.push([a,c]);return null};a._run_base_model_validator_registration=function(){Sirius.BaseModel.register_validator("length",Sirius.LengthValidator);Sirius.BaseModel.register_validator("exclusion",Sirius.ExclusionValidator);Sirius.BaseModel.register_validator("inclusion",
Sirius.InclusionValidator);Sirius.BaseModel.register_validator("format",Sirius.FormatValidator);Sirius.BaseModel.register_validator("numericality",Sirius.NumericalityValidator);return Sirius.BaseModel.register_validator("presence",Sirius.PresenceValidator)};a._Validators=[];a.attrs=[];a.skip=!1;a.guid_for=null;a.validate={};a.prototype.__name="BaseModel";a._attributes_are_logged=!1;return a}.call(this);Sirius.BaseModel._run_base_model_validator_registration();
Sirius.Collection=function(){var a=function(a,c){var b=this;c=void 0===c?{}:c;var e;if(!(a.prototype instanceof Sirius.BaseModel))throw Error("Collection must be used only with `BaseModel` inheritor");this._array=[];this.logger=Sirius.Application.get_logger(this.constructor.name);this._klass=a;this._type=a.name;this._indexes=c.index||[];if(0<this._indexes.length){var f=a.prototype.attrs().map(function(a){return Sirius.Utils.is_object(a)?Object.keys(a)[0]:a});this._indexes.forEach(function(a){if(-1===
f.indexOf(a))throw Error("Collection: field "+a+" from indexes: ["+this._indexes+"] is not exist in "+this._type);});this._indexes.forEach(function(a){b.logger.debug("create index for "+a+" field in "+b._type);return b["index_"+a]={}})}this._subscribers={};var g=this.constructor._EVENTS;c=0;for(e=g.length;c<e;c++)a=g[c],this._subscribers[a]=[];this.length=0};a.prototype.push=function(a){return this.add(a)};a.prototype.add=function(a){this._add(a)};a.prototype._add=function(a){var b=this;if(!a)throw Error("'"+
this._type+"' should not be null");if(null!=a.constructor){if(this._type!==a.constructor.name){var d="Require '"+this._type+"', but given '"+a.constructor.name+"'";this.logger.error("Collection: "+d);throw Error(d);}}else throw d="Seems '"+a+"' is not instance of "+this._type,this.logger.error(d),Error(d);this._array.push(a);0<this._indexes.length&&this._indexes.forEach(function(c){return b["index_"+c][a.get(c)]=b.length});this.length++;return this._gen("add",a)};a.prototype.remove=function(a){var b=
this;var d=this.index(a);null!==d&&(this._array.splice(d,1),this._gen("remove",a),this.length--,0<this._indexes.length&&this._indexes.forEach(function(c){delete b["index_"+c][a.get(c)];return Object.keys(b["index_"+c]).filter(function(a){return b["index_"+c][a]>d}).map(function(a){return--b["index_"+c][a]})}))};a.prototype.index=function(a){var b,d;var e=null;var f=this._array;var g=b=0;for(d=f.length;b<d;g=++b){var h=f[g];h.compare(a)&&(e=g)}return e};a.prototype.find=function(a,c){return this.find_all(a,
c)[0]||null};a.prototype.find_all=function(a,c){var b;if(0<this._indexes.length&&-1!==this._indexes.indexOf(a))return[this._array[this["index_"+a][c]]];var e=this._array;var f=[];var g=0;for(b=e.length;g<b;g++){var h=e[g];h.get(a)===c&&f.push(h)}return f};a.prototype.filter=function(a){a=void 0===a?function(){}:a;var b;var d=this._array;var e=[];var f=0;for(b=d.length;f<b;f++){var g=d[f];a.call(null,g)&&e.push(g)}return e};a.prototype.each=function(a){a=void 0===a?function(){}:a;var b;var d=this._array;
var e=[];var f=0;for(b=d.length;f<b;f++){var g=d[f];e.push(a.call(null,g))}return e};a.prototype.first=function(){return this._array[0]};a.prototype.last=function(){return this._array[this._array.length-1]};a.prototype.all=function(){return this._array};a.prototype.clear=function(){var a=this;this.length=0;this._array=[];if(0<this._indexes.length)return this._indexes.forEach(function(b){return a["index_"+b]={}})};a.prototype.map=function(a){return this.collect(a)};a.prototype.collect=function(a){return this._array.map(a)};
a.prototype.takeFirst=function(a){var b;var d=null;var e=this._array;var f=0;for(b=e.length;f<b;f++){var g=e[f];if(a(g)){d=g;break}}return d};a.prototype.size=function(){return this._array.length};a.prototype.to_json=function(){var a;var c=this._array;var d=[];var e=0;for(a=c.length;e<a;e++){var f=c[e];d.push(f.to_object())}return JSON.stringify(d)};a.prototype.subscribe=function(a,c){if(-1===this.constructor._EVENTS.indexOf(a))throw Error("For 'subscribe' method available only ["+this.constructor._EVENTS+
"], but given '"+a+"'");if(Sirius.Utils.is_string(c)||Sirius.Utils.is_function(c))this.logger.info("Add new subscriber for '"+a+"' event"),this._subscribers[a].push(c);else throw Error("Second parameter for 'subscribe' method must be a Function or a String, but '"+typeof c+"' given");};a.prototype._gen=function(a,c){for(var b=[],e=1;e<arguments.length;++e)b[e-1]=arguments[e];var f=this._subscribers[a];return Sirius.Application.get_adapter().and_then(function(a){var c;var d=[];var e=0;for(c=f.length;e<
c;e++){var g=f[e];Sirius.Utils.is_string(g)?d.push(a.fire.apply(a,[document,g].concat($jscomp.arrayFromIterable(b)))):d.push(g.apply(null,b))}return d})};a._EVENTS=["add","remove"];return a}.call(this);var lib$sirius$classdecl$var23=function(a,b){this.name=a;this.handler=b};Sirius.Internal.Listener=lib$sirius$classdecl$var23;var lib$sirius$classdecl$var24=function(a,b,c,d,e){this._from=a;this._to=b;this._attribute=c;this._transform=d;this._handle=e};
lib$sirius$classdecl$var24.prototype.has_to=function(){return null!=this._to};lib$sirius$classdecl$var24.prototype.has_attribute=function(){return null!=this._attribute};lib$sirius$classdecl$var24.prototype.has_transform=function(){return null!=this._transform};lib$sirius$classdecl$var24.prototype.has_handle=function(){return null!=this._handle};lib$sirius$classdecl$var24.prototype.field=function(){return this._from};lib$sirius$classdecl$var24.prototype.to=function(a){return null!=a?this._to=a:this._to};
lib$sirius$classdecl$var24.prototype.handle=function(a){return null!=a?this._handle=a:this._handle};lib$sirius$classdecl$var24.prototype.attribute=function(a){return null!=a?this._attribute=a:this._attribute};lib$sirius$classdecl$var24.prototype.transform=function(a){return null!=a?this._transform=a:this._transform};lib$sirius$classdecl$var24.prototype.normalize=function(){this.has_transform()||(this._transform=function(a){return a});if(!this.has_attribute())return this._attribute="text"};
lib$sirius$classdecl$var24.prototype.to_string=function(){var a=this._from instanceof Sirius.View?this._from.get_element():this._from._klass_name();var b=this._to instanceof Sirius.View?this._to.get_element():this._to instanceof Sirius.BaseModel?this._to._klass_name():this._to;return a+" ~> "+this._transform+" ~> "+b+"#"+this._attribute};lib$sirius$classdecl$var24.build=function(a){return new Sirius.FieldMaker(a)};Sirius.FieldMaker=lib$sirius$classdecl$var24;
var lib$sirius$classdecl$var25=function(a,b){this._from=a;this._to=b;this.fields=[];this.current=null;this.guid="Materializer#"+Sirius.Utils.guid();this.logger=Sirius.Application.get_logger(this.constructor.name)};lib$sirius$classdecl$var25.prototype.field=function(a){null!=this.current&&this.current.normalize();this.current=Sirius.FieldMaker.build(a);this.fields.push(this.current);return this};
lib$sirius$classdecl$var25.prototype._zoom_with=function(a,b){return Sirius.Utils.is_string(b)?a.zoom(b):b};lib$sirius$classdecl$var25.prototype.dump=function(){return this.fields.map(function(a){return a.to_string()}).join("\n")};lib$sirius$classdecl$var25.prototype.to_string=function(){return this.dump()};lib$sirius$classdecl$var25.prototype.get_from=function(){return this._from};lib$sirius$classdecl$var25.prototype.get_to=function(){return this._to()};
lib$sirius$classdecl$var25.prototype.has_to=function(){return null!=this._to};lib$sirius$classdecl$var25.prototype.fields_map=function(){var a;var b={};var c=this.fields;var d=0;for(a=c.length;d<a;d++){var e=c[d];b[e.field()]=e}return b};lib$sirius$classdecl$var25.prototype.run=function(){throw Error("Not Implemented");};Sirius.AbstractMaterializer=lib$sirius$classdecl$var25;var lib$sirius$classdecl$var26=function(){Sirius.AbstractMaterializer.apply(this,arguments)};
$jscomp.inherits(lib$sirius$classdecl$var26,Sirius.AbstractMaterializer);
lib$sirius$classdecl$var26.prototype.transform=function(a){if(!Sirius.Utils.is_function(a))throw Error("'transform' attribute must be function, "+typeof a+" given");if(null==this.current)throw Error("Incorrect call. Call 'transform' after 'to' or 'attribute'");if(!this.current.has_to())throw Error("Incorrect call. Call 'to' before 'transform'");if(this.current.has_transform())throw Error("Incorrect call. The field already has 'transform' function");this.current.transform(a);return this};
Sirius.MaterializerTransformImpl=lib$sirius$classdecl$var26;var lib$sirius$classdecl$var27=function(){Sirius.MaterializerTransformImpl.apply(this,arguments)};$jscomp.inherits(lib$sirius$classdecl$var27,Sirius.MaterializerTransformImpl);lib$sirius$classdecl$var27.prototype.field=function(a){var b=a;Sirius.Utils.is_function(a)&&(b=a(this._from.get_binding()));Sirius.Materializer._check_model_compliance(this._from,b);Sirius.MaterializerTransformImpl.prototype.field.call(this,b);return this};
lib$sirius$classdecl$var27.prototype.to=function(a){if(null==this.current)throw Error("Incorrect call. Call 'to' after 'field'");if(!(Sirius.Utils.is_function(a)||Sirius.Utils.is_string(a)||a instanceof Sirius.View))throw Error("'to' must be string or function, or instance of Sirius.View");var b=a;Sirius.Utils.is_string(a)&&(b=this._zoom_with(this._to,a));Sirius.Utils.is_function(a)&&(b=this._zoom_with(this._to,a(this._to)));if(this.current.has_to())throw Error("Incorrect call. '"+this.current.field()+
"' already has 'to'");this.current.to(b);return this};lib$sirius$classdecl$var27.prototype.attribute=function(a){if(null==this.current)throw Error("Incorrect call. Define 'field' firstly, and then call 'attribute' after 'to'");if(!this.current.has_to())throw Error("Incorrect call. Call 'to' before 'attribute'");if(this.current.has_attribute())throw Error("Incorrect call. '"+this.current.field()+"' already has 'attribute'");this.current.attribute(a);return this};
lib$sirius$classdecl$var27.prototype.to_attribute=function(a){return this.attribute(a)};lib$sirius$classdecl$var27.prototype.handle=function(a){if(null==this.current)throw Error("Incorrect call. 'field' is not defined");if(!this.current.has_to())throw Error("Incorrect call. define 'to'");if(!Sirius.Utils.is_function(a))throw Error("'handle' must be a function");if(this.current.has_handle())throw Error("'handle' already defined");this.current.handle(a);return this};
lib$sirius$classdecl$var27.prototype.run=function(){this.current.normalize();var a=this.fields_map();this._from._register_state_listener(new Sirius.Internal.Listener(this.guid,function(b,c){var d;b=Sirius.Materializer.get_necessary_functions(a,b);var e=[];var f=0;for(d=b.length;f<d;f++){var g=b[f];var h=g.transform().call(null,c,g.to());g.has_handle()?e.push(g.handle().call(null,g.to(),h)):e.push(g.to().render(h).swap(g.attribute()))}return e}))};lib$sirius$classdecl$var27.prototype.stop=function(){this._from._unregister_state_listener(this.guid)};
Sirius.ModelToViewMaterializer=lib$sirius$classdecl$var27;var lib$sirius$classdecl$var28=function(){Sirius.MaterializerTransformImpl.apply(this,arguments)};$jscomp.inherits(lib$sirius$classdecl$var28,Sirius.MaterializerTransformImpl);
lib$sirius$classdecl$var28.prototype.field=function(a){if(Sirius.Utils.is_string(a))a=this._from.zoom(a);else if(Sirius.Utils.is_function(a))a=this._zoom_with(this._from,a(this._from));else if(!(a instanceof Sirius.View))throw Error("Element must be string or function, or instance of Sirius.View");Sirius.MaterializerTransformImpl.prototype.field.call(this,a);return this};
lib$sirius$classdecl$var28.prototype.from=function(a){if(null==this.current)throw Error("Incorrect call. Define 'field' firstly, and then call 'from'");if(this.current.has_to())throw Error("Incorrect call. Call 'from' before 'to'");if(this.current.has_attribute())throw Error("Incorrect call. '"+this.current.field().get_element()+"' already has 'from'");this.current.attribute(a);return this};lib$sirius$classdecl$var28.prototype.from_attribute=function(a){return this.from(a)};
lib$sirius$classdecl$var28.prototype.to=function(a){if(null==this.current)throw Error("Incorrect call. Define 'field' firstly, and then call 'from'");if(this.current.has_to())throw Error("Incorrect call. '"+this.current.field().get_element()+"' already has 'to'");var b=a;null!=this._to&&Sirius.Utils.is_function(a)&&(b=a(this._to.get_binding()));null!=this._to&&this._to instanceof Sirius.BaseModel&&Sirius.Materializer._check_model_compliance(this._to,b);this.current.to(b);return this};
lib$sirius$classdecl$var28.prototype.run=function(){var a;this.current.normalize();var b=this._to;var c=function(a){return function(c){c=a.transform().call(null,c);return-1!==a.to().indexOf(".")?b.set_error(a.to(),c):b.set(a.to(),c)}};var d=this.fields;var e=0;for(a=d.length;e<a;e++){var f=d[e];var g=c(f);g=new Sirius.Internal.Observer(f.field().get_element(),f.attribute(),g);f.field()._register_state_listener(new Sirius.Internal.Listener(this.guid,g))}};
lib$sirius$classdecl$var28.prototype.stop=function(){var a,b;var c=this.guid;var d=this.fields;var e=0;for(a=d.length;e<a;e++){var f=d[e];var g=f.field()._unregister_state_listener(c);this.logger.debug("Stop observers "+g.length+" for "+f.field());f=0;for(b=g.length;f<b;f++){var h=g[f];h.handler.stop()}}};Sirius.ViewToModelMaterializer=lib$sirius$classdecl$var28;var lib$sirius$classdecl$var29=function(){Sirius.ViewToModelMaterializer.apply(this,arguments)};
$jscomp.inherits(lib$sirius$classdecl$var29,Sirius.ViewToModelMaterializer);lib$sirius$classdecl$var29.prototype.to=function(a){if(Sirius.Utils.is_string(a))a=this._to.zoom(a);else if(!(a instanceof Sirius.View))if(Sirius.Utils.is_function(a))a=this._zoom_with(this._to,a(this._to));else throw Error("Element must be string or function, or instance of Sirius.View");Sirius.ViewToModelMaterializer.prototype.to.call(this,a);return this};
lib$sirius$classdecl$var29.prototype.handle=function(a){if(null==this.current)throw Error("Incorrect call. 'field' is not defined");if(!this.current.has_to())throw Error("Incorrect call. define 'to'");if(!Sirius.Utils.is_function(a))throw Error("'handle' must be a function");if(this.current.has_handle())throw Error("'handle' already defined");this.current.handle(a);return this};
lib$sirius$classdecl$var29.prototype.run=function(){var a;this.current.normalize();var b=function(a){return function(b){b=a.transform().call(null,b);return a.has_handle()?a.handle().call(null,a.to(),b):a.to().render(b).swap()}};var c=this.fields;var d=0;for(a=c.length;d<a;d++){var e=c[d];var f=new Sirius.Internal.Observer(e.field().get_element(),e.attribute(),b(e));e.field()._register_state_listener(new Sirius.Internal.Listener(this.guid,f))}};Sirius.ViewToViewMaterializer=lib$sirius$classdecl$var29;
var lib$sirius$classdecl$var30=function(){Sirius.ViewToModelMaterializer.apply(this,arguments)};$jscomp.inherits(lib$sirius$classdecl$var30,Sirius.ViewToModelMaterializer);lib$sirius$classdecl$var30.prototype.to=function(a){if(!Sirius.Utils.is_function(a))throw Error("Function is required");Sirius.ViewToModelMaterializer.prototype.to.call(this,a);return this};
lib$sirius$classdecl$var30.prototype.run=function(){var a;this.current.normalize();var b=this.fields;var c=0;for(a=b.length;c<a;c++){var d=b[c];var e=new Sirius.Internal.Observer(d.field().get_element(),d.attribute(),d.to());d.field()._register_state_listener(new Sirius.Internal.Listener(this.guid,e))}};Sirius.ViewToFunctionMaterializer=lib$sirius$classdecl$var30;var lib$sirius$classdecl$var31=function(){Sirius.AbstractMaterializer.apply(this,arguments)};
$jscomp.inherits(lib$sirius$classdecl$var31,Sirius.AbstractMaterializer);lib$sirius$classdecl$var31.prototype.field=function(a){var b=a;Sirius.Utils.is_function(a)&&(b=a(this._from.get_binding()));Sirius.Materializer._check_model_compliance(this._from,b);Sirius.AbstractMaterializer.prototype.field.call(this,b);return this};
lib$sirius$classdecl$var31.prototype.to=function(a){if(null==this.current)throw Error("Incorrect call. Define 'field' firstly");if(this.current.has_to())throw Error("Incorrect call. The field already has 'to'");if(!Sirius.Utils.is_function(a))throw Error("Function is required");this.current.to(a);return this};
lib$sirius$classdecl$var31.prototype.run=function(){var a=this.fields_map();this._from._register_state_listener(new Sirius.Internal.Listener(this.guid,function(b,c){var d;b=Sirius.Materializer.get_necessary_functions(a,b);var e=[];var f=0;for(d=b.length;f<d;f++){var g=b[f];e.push(g.to().call(null,c))}return e}))};lib$sirius$classdecl$var31.prototype.stop=function(){return this._from._unregister_state_listener(this.guid)};Sirius.ModelToFunctionMaterializer=lib$sirius$classdecl$var31;
Sirius.Materializer=function(){var a=function(a,c){if(a instanceof Sirius.BaseModel&&c instanceof Sirius.View)return new Sirius.ModelToViewMaterializer(a,c);if(a instanceof Sirius.View&&c instanceof Sirius.BaseModel)return new Sirius.ViewToModelMaterializer(a,c);if(a instanceof Sirius.View&&c instanceof Sirius.View)return new Sirius.ViewToViewMaterializer(a,c);if(a instanceof Sirius.View&&null==c)return new Sirius.ViewToFunctionMaterializer(a);if(a instanceof Sirius.BaseModel&&null==c)return new Sirius.ModelToFunctionMaterializer(a);
throw Error("Illegal arguments: 'from'/'to' must be instance of Sirius.View/or Sirius.BaseModel");};a._check_model_compliance=function(a,c){var b=a._klass_name();var e=a.get_attributes();if(-1!==e.indexOf(c)||c===Sirius.Internal.Errors+".all")return!0;if(-1===c.indexOf("."))throw Error("Attribute '"+c+"' not found in model attributes: '"+b+"', available: '["+e+"]'");e=c.split(".");if(3!==e.length)throw Error("Try to bind '"+c+"' from errors properties, but validator is not found, correct definition should be as 'errors.id.numericality'");
var f=$jscomp.makeIterator(e);f.next();e=f.next().value;f=f.next().value;if("all"===f||a._is_valid_validator(e+"."+f))return!0;throw Error("Unexpected '"+c+"' errors attribute for '"+b+"' (check validators)");};a.get_necessary_functions=function(a,c){var b=[];if(c.startsWith(Sirius.Internal.Errors)){null!=a[Sirius.Materializer.errors_all]&&b.push(a[Sirius.Materializer.errors_all]);var e=$jscomp.makeIterator(c.split("."));e.next();var f=e.next().value;e.next();f=Sirius.Internal.Errors+"."+f+".all";
null!=a[f]&&b.push(a[f])}null!=a[c]&&b.push(a[c]);return b};a.build=function(a,c){return new Sirius.Materializer(a,c)};a.errors_all=Sirius.Internal.Errors+".all";return a}.call(this);