(function(){u8.Base.FormOrderGroup=function(e){$.extend(this,u8.Base.FormOrderGroup.defaults,e);this.orders=new u8.Base.Model;this._checkBoxIds={};this._ordered=[];var r=u8.Base.Widgets.Form.getForm(this);r.bind("WidgetCreate",this._onFormWidgetCreate.bind(this));this.orders.bind("PropertyChange",this._onOrdersPropertyChange.bind(this))};u8.Base.FormOrderGroup.makeClass({name:"FormOrderGroup"});u8.Base.FormOrderGroup.defaults={};$.extend(u8.Base.FormOrderGroup.prototype,{_onFormWidgetCreate:function(e,r){if(u8.tools.isInstanceOfClass(r.widget,"CheckBox")&&r.widget.orderGroupName==this.orderGroupName){this._checkBoxIds[r.widget.id]=r.widgetId;r.widget._FormOrderGroup_label=r.widget.label;this._updateCheckBox(r.widget,this.orders.get(r.widgetId));r.widget.bind("ValueChange",this._onCheckBoxValueChange.bind(this))}},_updateCheckBox:function(e,r){if(r>=0){e.attr({label:e._FormOrderGroup_label+" ("+((r|0)+1)+")"})}else{e.attr({label:e._FormOrderGroup_label})}},_onCheckBoxValueChange:function(e,r){if(r.value==e.trueValue){if(this._ordered.indexOf(e.id)>=0){return}this._ordered.push(e.id)}else{var t=this._ordered.indexOf(e.id);if(t<0){return}this._ordered.splice(t,1)}var d=u8.Base.Widgets.Form.getForm(this);this._ignoreOrdersPropertyChange=true;for(var i in this._checkBoxIds){var o=this._checkBoxIds[i];var s=this.orders.get(o);var a=this._ordered.indexOf(i);if(s!=a){this.orders.set(o,a);var n=d.getWidget(o);this._updateCheckBox(n,a)}}this._ignoreOrdersPropertyChange=false},_onOrdersPropertyChange:function(e,r){if(this._ignoreOrdersPropertyChange){return}var t=u8.Base.Widgets.Form.getForm(this);var d=this;if(!t._isCreated){if(!this._addedFormCreateEvent){t.bind("Create",i);this._addedFormCreateEvent=true}}else{i()}function i(){var e={};var r=d.orders.getProperties();var i;for(var o in r){var s=t.getWidget(o);i=s.id;var a=r[o];var n=d._ordered.indexOf(i);e[a]=i;if(n!=a){d._updateCheckBox(s,a)}}d._ordered=[];for(var h=0;true;h++){i=e[h];if(!i){break}d._ordered.push(i)}delete d._addedFormCreateEvent}}})})();