Application.define("core.view_model",function(a){a=jQuery.extend(!0,{_required:{},scope:!1,model:{},view:!1,container:!1,args:{l10n:{remove_confirmation:"Are you sure you want to remove it?"}},actions:{update:function(){return null},pre_apply:function(a,b){b(null,!0)},init:function(a,b){b(null,!0)},add_data:function(){return null},remove_data:function(){return null},callback:!1},callback:function(a,b){var c=this;return"object"==typeof c.actions&&"function"==typeof c.actions.callback?c.actions.callback(a,b):(a&&a instanceof Error&&console.error(a.message,b),b)}},"object"==typeof a?a:{});var b=a.container&&"object"!=typeof a.container?jQuery(a.container):a.container;if(!b||"undefined"==typeof b.length||!b.length>0)return a.callback(new Error("ko.view_model. Container is missing, or incorrect."),!1);a.view&&(/^((https?|ftp):)?\/\/([\-A-Z0-9.]+)(\/[\-A-Z0-9+&@#\/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#\/%=~_|!:,.;]*)?/i.test(a.view)&&jQuery.ajax({url:a.view,async:!1,dataType:"html",complete:function(b){a.view=b.responseText}}),b.html(a.view));var c=b.html();b.html("").addClass("ud_view_model ud_ui_loading").append('<div class="ud_ui_spinner"></div>').append('<div class="ud_ui_prepared_interface"></div>').find(".ud_ui_prepared_interface").html(c);var d=function(a,b){var c=this;c._applied=!1,c._args=a,c.scope=a.scope,c.core=a.scope.core,c.socket="object"==typeof a.scope.socket?a.scope.socket:!1,c.container=b,c.add_data=function(a,b,d,e){"function"==typeof b?a.push(new b):"function"==typeof d[b]&&a.push(new d[b]);try{c._args.actions.add_data(c,e,a,b)}catch(f){c._args.callback(f,d)}},c.alert=function(a,b){var d="alert-success";if("undefined"!=typeof b)switch(b){case"error":d="alert-error";break;case"warning":d=""}var e='<div class="container alert fade in '+d+'"><button type="button" class="close" data-dismiss="alert">&times;</button>'+a+"</div>";c.container.prepend(e)},c.remove_data=function(a,b,d){confirm(c.l10n.remove_confirmation)&&a.remove(b);try{c._args.actions.remove_data(c,d,a,b)}catch(e){c._args.callback(e,c)}},c.apply=function(a){var b=this,c=b.container.get(0);return b._applied?b._args.callback(null,b,c):(async.series({pre_apply:function(a){try{b._args.actions.pre_apply(b,a)}catch(c){a("Error occured on VM pre_apply event")}},apply_bindings:function(a){ko.applyBindings(b,b.container.get(0)),b._applied=!0,a(null,!0)},init:function(a){b.container.removeClass("ud_ui_loading").addClass("ud_ui_applied");try{b._args.actions.init(b,a)}catch(c){a("Error occured on VM init event")}}},function(){return b.update("undefined"!=typeof a?a:[]),b._args.callback(null,b)}),null)},c.update=function(a){var b=this;try{b._args.actions.update(b,"undefined"!=typeof a?a:[])}catch(c){b._args.callback(c,b)}};var d={},a={};("object"==typeof c._args.model?c._args.model:{})&&jQuery.each(c._args.model,function(b,e){"undefined"==typeof c._args[b]?d[b]=e:a[b]=e}),c._args=jQuery.extend(!0,c._args,a),c=jQuery.extend(!0,c,"object"==typeof c._args.args?c._args.args:a,d)};return new d(a,b)});