(function(){"use strict";u8.Mobile.Widgets.View=function(e,t){this.MobileWidget(e,$.extend({},u8.Mobile.Widgets.View.defaults,t));this._create()};u8.Mobile.Widgets.View.defaults={};$.extend(u8.Mobile.Widgets.View.prototype,{load:function(t){if(typeof t=="string"){t={url:t}}var i=this,r=t.url;if(!r){return $.Deferred().reject({error:{message:"Failed to load view! Missing argument 'url'!"}}).promise()}if(this._rest){this.abort()}this.setState("loading");var n=this._transitionOut(t);var s=t.method||this.method;var a=t.data||this.data;var o=new u8.Base.Uri(r);if(o.params.tileName!="Tile:RecentlyUsed"){r=e(r)}this._rest=u8.rest({url:r,data:a,contentType:t.contentType,dataType:t.dataType,method:s,headers:{"x-view":this.view||"partial"}}).fail(function(e){if(i._isDisposed||e&&e.status=="abort"){return}i._rest=null;i.error(e);i.setState("ready")}).done(function(e){if(i._isDisposed){return}i._rest=null;i.value=r;l(e)});function l(e){if(typeof e!="string"){return i.update(e,t)}n.done(function(){i.update(e,t);i.setState("ready");i.raise("Load");i._transitionIn(t)})}return this._rest},error:function(e){this.$element.widgets("dispose").empty();var t=e&&e.data;if(!t){t="<div class='alert alert-danger'>An unknown error occurred.</div>"}if(t.indexOf("<!DOCTYPE")>=0){var i=document.implementation.createHTMLDocument("");i.documentElement.innerHTML=t;if(this.view=="full"){var r=t.indexOf("alert alert-danger")<0;if(r){t="<div class='alert alert-danger container u8-margin-top'>"+i.body.innerHTML+"</div>"}else{t=i.body.innerHTML}}else{t="<div class='alert alert-danger'>"+i.body.innerHTML+"</div>"}}this.$element.html(t)},abort:function(){if(this._rest){this._rest.abort();this._rest=null}},dispose:function(){if(this._isDisposed){return}this.abort();this.MobileWidget_dispose()},update:function(e,t){if(typeof e=="object"){return u8.application.execute(e,$.extend({source:this},t))}if(typeof e!="string"){return}this._updateView(e,t);this._processView()},_create:function(){var e=this.value;if(e){this.load({url:e})}else{if(this.element.innerHTML){this._processView()}}},_updateView:function(e,t){var i=$.extend({data:e},t);this.bubble("View.onPreUpdate",i);if(i.cancel){return}if(!i.preventDefault){this.$element.widgets("dispose");var r=this.element.classList.contains("shim");if(r){this._replaceShim(e)}else{this.element.innerHTML=e}}this.bubble("View.onUpdate",i)},_processView:function(){var e={};this.bubble("View.onPreProcess",e);if(e.cancel){return}if(!e.preventDefault){this.$element.widgets("apply-behaviors").widgets("create-visible");if(this.enableValidation){this.$element.find(".field-validation-error").each(function(){$(this).closest(".control-group").addClass("error")});$.validator.unobtrusive.parse(this.element)}}this.bubble("View.onProcess",e)},_replaceShim:function(e){var t=document.createElement("div");t.innerHTML=e;var i=t.children;if(!i||!i.length){return}var r=i[0];r.id=this.id;this.element.parentNode.replaceChild(r,this.element);this.element=r;this.$element=$(r);var n=r.parentNode,s=r.nextSibling;while(i.length>0){n.insertBefore(i[0],s)}},_transitionIn:function(e){var t=e&&e.direction||"forward";var i=this.$element.find(".u8-transition-in");if(i){i.removeClass("u8-transition-in")}var r=$.Deferred();var n=i&&i.length&&!i.is(":empty");if(n){var s="u8-transition-in-"+t;i.addClass(s).one("animationend",function(){this.classList.remove(s);r.resolve()})}else{r.resolve()}return r.promise()},_transitionOut:function(e){var t=e.transition||this.transition;var i=t&&(t.selector?this.$element.find(t.selector):this.$element);var r={};if(!i||!i.length||i.is(":empty")){return $.Deferred().resolve(r).promise()}e.transition=r;var n=e&&e.direction||"forward";var s=$.Deferred();var a="u8-transition-out-"+n;i.addClass(a).one("animationend",function(){this.classList.remove(a);s.resolve(r)});return s.promise()}});u8.Mobile.Widgets.View.makeClass({name:"View",deriveFrom:u8.Mobile.Widgets.MobileWidget,events:["Load"]});function e(e){if(typeof e=="string"){e=new u8.Base.Uri(e)}var t=page.url.params;var i=e.params;Object.keys(i).forEach(function(e){var r=i[e];if(typeof r!="string"){return}var n=false;r=r.format(function(e){n=true;return t[e]||""});if(n&&!r){delete i[e]}else{i[e]=r}});e=e.toString_();return e}})();