text: JRS.Controls=function(t,e,n){var i=n.Base.extend({constructor:function(t){this.containerSelector=t&&t.containerSelector||n.ViewModel.DEFAULT_CONTAINER,this.controls={},n.getViewModel=e.bind(function(){return this},this),e.bindAll(this),this.registerEvents()},registerEvents:function(){n.ignore("changed:control",this.onControlChange),n.listen({"changed:control":this.onControlChange})},onControlChange:function(i,o){var r,s=o.slaveDependencies&&o.slaveDependencies.length;if(s){var a=this._getAllSlaveControlIds(o.id),l=this._getParentControlIds(a),c=e.union(a,l);r=this.get("selection"),e.isEmpty(c)||e.each(r,function(t,n){-1===e.indexOf(c,n)&&delete r[n]})}else r=this.get("selection");t(document).trigger(n.ViewModel.CHANGE_SELECTION,[r,a,s]),s||t(document).trigger(n.ViewModel.CHANGE_VALUES,[this.state])},_getAllSlaveControlIds:function(t){var n=[],i=this.findControl({id:t});return i&&!e.isEmpty(i.slaveDependencies)&&e.each(i.slaveDependencies,function(t){n.push(t),n.push.apply(n,this._getAllSlaveControlIds(t))},this),e.uniq(n)},_getParentControlIds:function(t){var n=[];return e.each(t,function(t){var e=this.findControl({id:t});n.push.apply(n,e.masterDependencies)},this),e.uniq(n)}},{DEFAULT_CONTAINER:"#inputControlsContainer",CHANGE_VALUES:"viewmodel:values:changed",CHANGE_SELECTION:"viewmodel:selection:changed",CHANGE_ORDER:"viewmodel:order:changed",isSelectionChanged:function(t,n){var i=t?e(t).keys():[],o=n?e(n).keys():[],r=e.union(i,o);if(r.length===i.length){var s=t?e.flatten(e(t).values()):[],a=n?e.flatten(e(n).values()):[];return e.difference(s,a).length>0||e.difference(a,s).length>0}return!0}}),o={getControls:function(){return this.controls},instantiate:function(t){this.controls={},e.each(t,this.createControl,this)},createControl:function(t){var e=function(t){for(var e in n)if(t.toLowerCase()===e.toLowerCase())return n[e]}(t.type);if(!e)throw new Error("Can not find implementation of the control type: "+t.type);return this.controls[t.id]=new e(t),this.controls[t.id]},removeControl:function(t){delete this.controls[t]},reorderControl:function(e,i){if(1!=this.structure.length){for(var o,r=i>e?1:-1,s=i>e?Math.min(e,i):Math.max(e,i),a=i>e?Math.max(e,i):Math.min(e,i),l=s;l!=a;l+=r)o=this.structure[l],this.structure[l]=this.structure[l+r],this.structure[l+r]=o;t(document).trigger(n.ViewModel.CHANGE_ORDER,[this.structure])}},set:function(i,o){if(i){if(e.extend(this,i),void 0!==i.structure){var r=i.structure;this.instantiate(r),this.draw(r)}if(void 0!==i.state){var s=i.state;this.update(s),!o&&t(document).trigger(n.ViewModel.CHANGE_VALUES,[i.state])}}},get:function(t){if(t){if("selection"===t){var n={};return e.each(this.getControls(),function(t){var i=t.get("selection");i instanceof Array?n[t.id]=i:e.isUndefined(i)||(n[t.id]=[i])}),n}return this[t]}},findControl:function(t){var n=e.keys(t)[0],i=e.values(t)[0];return e.find(this.getControls(),function(t){return t[n]===i})},pluck:function(t){return e.pluck(this.getControls(),t)}},r={draw:function(n){var i=this.getContainer();if(i.empty(),e.each(n,function(t){if(t.visible){var e=this.findControl({id:t.id});e.makeResizable&&e.makeResizable(),i.append(e.getElem())}},this),window.Report&&window.Report.icReorderEnabled){var o=window.Controls.layouts.LAYOUT_TOP_OF_PAGE==Report.reportControlsLayout;/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)||t(i).sortable({delay:200,placeholder:o?"verticalPlaceholder":"horizontalPlaceholder",axis:o?"x":"y",items:"> .leaf",cancel:"input,textarea,button,select,option,.list.inputSet",start:function(t,e){e.item.data("oldIndex",e.item.index())},stop:e.bind(function(t,e){var n=e.item.data("oldIndex"),i=e.item.index();n!=i&&this.reorderControl(n,i)},this)})}},update:function(t){e.each(t,function(t,e){var n=this.findControl({id:e});n.set({values:t.values,error:t.error})},this)},getContainer:function(){return this.container&&1==this.container.length?this.container:(this.container=t(this.containerSelector),this.container)},removeValidationMessages:function(){e.each(this.getControls(),function(t){t.set({error:null})})},areAllControlsValid:function(){return e.isEmpty(e.filter(this.getControls(),function(t){return!t.isValid()}))},setContainer:function(e){this.container=t(e)},reloadContainer:function(){return this.container=t(this.containerSelector),this.container},disable:function(){e.each(this.getControls(),function(t){t.set({disabled:!0})})},enable:function(){e.each(this.getControls(),function(t){t.set({disabled:!1})})}};return e.extend(i.prototype,o,r),e.extend(n,{ViewModel:i})}(jQuery,_,JRS.Controls);