(function(){"use strict";var e=u8.Mobile.Widgets.MobileWidget;function t(e,n){this.MobileWidget(e,$.extend({},t.defaults,n))}t.defaults={childWidgetCreationMode:"create"};t.prototype={getField:function(e){if(!e){return null}if(typeof e=="object"){var t=$(e);var n=t.attr("data-role");if(n!="field"){t=t.closest("[data-role='field']")}if(!t.length){return null}return t.widgets()[0]}var i=this.$element.find("[data-name='"+e+"']");return this.getField(i[0])},setValue:function(e,t){var n=this.getField(e);if(!n){u8.log.warn("Expand: Ignoring attempt to set value of unknown field named '"+e+"' to value "+JSON.stringify(t)+".")}else{n.setValue(t)}},addLink:function(e){var t=this.$element.find("input[name='links']");var d=Number(t.toArray().map(a).max(-1));var l=n(e);var o=this.$element.find("input[data-link='"+l+"']");if(!o.length){o=$("<input type='hidden' name='links' />").attr("data-link",l).prependTo(this.$element.find("form"))}o.val(i(e));r(o,d+1);this.raise("Change",{reason:"links"})},getLinks:function(){var e=this.$element.find("input[name='links']");var t=e.toArray().sort(u8._.cmp([a],true));var n=t.map(function(e){return $(e).val()});if(this.link){n.unshift(i(this.link))}return n},submit:function(e){var t=e.data;var n=$(e.srcElement).find("button[type=submit]");n.addClass("disabled");$(document).ajaxError(function(){n.removeClass("disabled")});this.children().each(function(e){if(typeof e["Expand.save"]!="function"){return}if(!t.children){t.children=[]}e["Expand.save"](t)})},"Selector.canSelect":function(e){return e.type=="record"},"Selector.select":function(e){var t=e.fields;for(var n in t){var i=this.getField(n);if(i){i.setValue(t[n])}}var a=e.links;for(var r=0;a&&r<a.length;r++){this.addLink(a[r])}},create:function(){var t=this.$element.find("[data-role='field']");t.widgets("create");e.prototype.create.call(this)}};t.makeClass({name:"Expand",deriveFrom:e,events:["Change"]});function n(e){if(!e){return""}return e.infoAreaId+"/"+e.linkId}function i(e){if(!e){return""}return e.infoAreaId+"/"+e.recordId+"/"+e.linkId}function a(e){var t=$(e).attr("data-timestamp");return t===undefined?0:t}function r(e,t){return $(e).attr("data-timestamp",t)}})();