namespace("widgets.applicationCategoryList");widgets.applicationCategoryList.MultipleCategorySelectionModeViewBase=Backbone.View.extend({initialize:function(n){_.extend(this,n)},getValueSchema:function(){var t=this.model.map(function(n){return n.get("code")}),n=Joi.array().items(Joi.string().valid(t));return _.isNullOrUndefined(this.settings.multipleSelectedCategoryCountLimit)?n:n.max(this.settings.multipleSelectedCategoryCountLimit)},validateValue:function(n){return this.getValueSchema().required().validate(n,{abortEarly:!1,convert:!1})},toggleDisabledState:function(){throw new Error("Not Implemented");}}),function(n){n.extend(n.fn,{applicationCategoryList:function(n,t){var r,i,u;return this.length?(r=this.is(".applicationCategoryList")?this:this.find(".applicationCategoryList"),!r.length)?undefined:(i=r.data("applicationCategoryList"),i)?i:(t||(t={mode:"CheckboxList"}),t.mode||(t.mode="CheckboxList"),u={el:r,model:n instanceof Backbone.Collection?n:new Backbone.Collection(n),settings:t},i=t.mode=="CheckboxList"?new widgets.applicationCategoryList.CheckboxListSelectionModeView(u):new widgets.applicationCategoryList.MultipleDropDownSelectionModeView(u),r.data("applicationCategoryList",i),i.render(),i):undefined}})}(jQuery);namespace("widgets.applicationCategoryList");widgets.applicationCategoryList.CheckboxListSelectionModeView=widgets.applicationCategoryList.MultipleCategorySelectionModeViewBase.extend({events:{"click .checkAll":"onCheckAllClicked","click .uncheckAll":"onUncheckAllClicked","click .selectCategory":"onSelectCategoryClicked"},initialize:function(n){var t,i,r;this.constructor.__super__.initialize.call(this,n);this.$el.addClass("applicationCategoryList");this.settings.columns=_.isArray(this.settings.columns)?this.settings.columns:[];t=this.$(".selectCategory");t.enableAtLeastOneCheckedValidationRule(!0);i=t.last();r=i.attr("name");i.parent().addErrorContainerIfNotExists(r);t.on("change",function(){$(this).closest("form").validate().element('[name="'+r+'"]')})},render:function(){this.list=this.$el;this.toggleCategoryCheckboxesDisabledStateIfNeeded()},getValue:function(){return _(this.getSelectedLeafCategoryIds()).map(function(n){return this.model.get(n).get("code")},this)},setValueWithoutValidation:function(n){var t=this,i=_(n).map(function(n){return t.model.findWhere({code:n}).id});_(this.getSelectedCategoryIds()).chain().difference(i).each(function(n){t._checkCategoryById(n,!1);t.toggleCategoryCheckboxesDisabledStateIfNeeded()});_(i).each(function(n){t._checkCategoryById(n,!0);t.checkChildCategoriesFor(n,!0);t.checkParentCategoriesFor(n,!0);t.toggleCategoryCheckboxesDisabledStateIfNeeded();t.trigger("categorySelected",{categoryIds:t.getSelectedLeafCategoryIds(),lastSelectedId:n})});t.renderSelectedCategoryIds()},toggleDisabledState:function(n){$(this.list).find("input:not([type='hidden'], .disabledByCategoryCountLimit)").toggleDisabledFromJsApiState(n)},onSelectCategoryClicked:function(n){var t=$(n.target).attr("data-id"),i=$(n.target).is(":checked");this.checkChildCategoriesFor(t,i);this.checkParentCategoriesFor(t,i);this.renderSelectedCategoryIds();this.toggleCategoryCheckboxesDisabledStateIfNeeded();this.trigger("categorySelected",{categoryIds:this.getSelectedLeafCategoryIds(),lastSelectedId:t})},onCheckAllClicked:function(){$(this.list).find(".selectCategory").prop("checked",!0)},onUncheckAllClicked:function(){$(this.list).find(".selectCategory").prop("checked",!1)},checkChildCategoriesFor:function(n,t){var i=this.model.chain().filter(function(t){return t.get("parentId")==n}).map(function(n){return n.get("id")}).value(),r;i&&(r=this,_(i).each(function(n){r._checkCategoryById(n,t)}),_(i).each(function(n){r.checkChildCategoriesFor(n,t)}))},checkParentCategoriesFor:function(n,t){var e=this.model.get(n),i=e.get("parentId"),r,u,f;i&&(r=this.model.chain().filter(function(n){return n.get("parentId")==i}).map(function(n){return n.get("id")}).value(),r)&&(u=!1,f=this,t||(u=_(r).all(function(n){return!f.$("input[data-id ="+n+"]").is(":checked")})),(t||u)&&(this._checkCategoryById(i,t),this.checkParentCategoriesFor(i,t)))},getSelectedCategoryIds:function(){var n=[];return $(this.list).find(".selectCategory:checked").each(function(){n.push($(this).attr("data-id").asInt())}),n},checkSelectedCategoryPath:function(){var t=this.getSelectedCategoryIds(),n=this;_(t).each(function(t){n.checkChildCategoriesFor(t,!0);n.checkParentCategoriesFor(t,!0)})},getSelectedLeafCategoryIds:function(){var n=this.getSelectedCategories(),t=[];return _(_(n).pluck("id")).each(function(i){var r=_(n).filter(function(n){return n.get("parentId")==i});r.length||t.push(i)}),t},getSelectedCategories:function(){var n=this.getSelectedCategoryIds();return this.model.filter(function(t){return _(n).contains(t.id)})},getAllCategories:function(){return this.model},checkCategories:function(n){var t=this;_(n).each(function(n){t.$("input[data-id ="+n+"]").prop("checked",!0)})},toggleCategories:function(n){var t=this;_(n).each(function(n){t.$("input[data-id ="+n+"]").click()})},renderSelectedCategoryIds:function(){var n=this.$(".selectedCategoryIds"),t=n.attr("data-inputName");n.empty();_(this.getSelectedLeafCategoryIds()).each(function(i,r){n.append("<input type='hidden' name='"+t+"["+r+"]' value='"+i+"' />")})},toggleCategoryCheckboxesDisabledStateIfNeeded:function(){if(this.settings.multipleSelectedCategoryCountLimit){var i=this.getSelectedLeafCategoryIds(),n=this.$("input.selectCategory:not(:checked)"),t=i.length>=this.settings.multipleSelectedCategoryCountLimit;n.toggleClass("disabledByCategoryCountLimit",t);n.prop("disabled",t)}},_checkCategoryById:function(n,t){var i=this.$("input[data-id ="+n+"]");(!i.attr("disabled")||i.hasClass("readOnly")||i.hasClass("disabledByCategoryCountLimit"))&&i.prop("checked",t)}});namespace("widgets.applicationCategoryList");widgets.applicationCategoryList.MultipleDropDownSelectionModeView=widgets.applicationCategoryList.MultipleCategorySelectionModeViewBase.extend({categorySelectorCount:0,categorySelectorOrder:0,events:{"click .remove":"onRemoveClicked","click .add":"onAddClicked"},render:function(){var i=this.$el.closest("section").find("label.name").text().trim(),n,t,r;if(this.applicationCategoryFieldName=i,n=this.$("a.add"),n.text(n.text().replace("{ApplicationCategoryFieldName}",i)),t=this.$(".selectedCategories input"),!t.length){this.addNewCategorySelector();return}r=this;_(t).each(function(n){var t=$(n).attr("data-path");r.addNewCategorySelector().selectPath(t,"_")});this.renderSelectedCategories();this.toggleAddButtonIfNeeded();this.settings.readOnly&&this.$("a.remove").hide()},getValue:function(){return _(this.getSelectedCategoryIds()).map(function(n){return this.model.get(n).get("code")},this)},setValueWithoutValidation:function(n){_(this.$(".hierarchyItemSelector")).each(function(n){this.removeCategorySelector($(n))},this);_.isEmpty(n)?this.addNewCategorySelector():_(n).each(function(n){this.addNewCategorySelector().selectItem(this.model.findWhere({code:n}).id)},this)},toggleDisabledState:function(n){this.$(".hierarchyItemSelector select").toggleDisabledFromJsApiState(n);this.$("a.add").toggle(!n);this.$("a.remove:not(:first)").toggle(!n)},onRemoveClicked:function(n){var r=$(n.target).next(".hierarchyItemSelector"),u=r.hierarchyItemSelector(),t=u.getSelectedValue(),i;if(!t||!u.isLeaf(t)){this.removeCategorySelector(r);_.isUndefined(t)||this.trigger("categorySelected",{categoryIds:this.getSelectedCategoryIds(),lastSelectedId:t});return}i=this;Confirmation.requestDelete({itemName:this.applicationCategoryFieldName,callback:function(){i.removeCategorySelector(r);i.trigger("categorySelected",{categoryIds:i.getSelectedCategoryIds(),lastSelectedId:t})}})},onAddClicked:function(){this.addNewCategorySelector()},onItemChanged:function(n){this.renderSelectedCategories();this.trigger("categorySelected",{categoryIds:this.getSelectedCategoryIds(),lastSelectedId:n})},addNewCategorySelector:function(){var n,i,t,r;return this.$(".categorySelectorList").append($.templates("#categorySelectorTmpl").render()),n=this.$(".categorySelectorList .hierarchyItemSelector").last(),this.categorySelectorOrder++,this.categorySelectorCount++,i=this,_(n.find("select")).each(function(n){var t=$(n),r;t.attr("name",t.attr("name")+"-"+i.categorySelectorOrder);r=t.hasClass("required");t.enableRequiredValidationRule(r);r&&t.addErrorContainerIfNotExists()}),t=n.prev("a.remove"),t.text(t.text().replace("{ApplicationCategoryFieldName}",this.applicationCategoryFieldName)),r=n.hierarchyItemSelector({el:n,mode:"DropDown"}).on("itemChanged",this.onItemChanged,this),this.renderSelectedCategories(),r},getSelectedCategoryIds:function(){var n=[];return _(this.$(".categorySelectorList .hierarchyItemSelector")).each(function(t){var i=$(t).hierarchyItemSelector().getSelectedValue();_.isNullOrUndefined(i)||n.push(i)}),n},renderSelectedCategories:function(){var n=this.$(".selectedCategories"),i=n.attr("data-inputName"),t;n.empty();t=this.getSelectedCategoryIds();_(t).each(function(t,r){_.isUndefined(t)||n.append("<input type='hidden' name='"+i+"["+r+"]' value='"+t+"' />")});_(this.$(".categorySelectorList .hierarchyItemSelector")).each(function(n,i){var r=$(n).hierarchyItemSelector();r.clearAllItemsDisabledState();r.setItemsDisabledState(t,!0);r.setInputName("SelectedPath["+i+"]");r.renderSelectedPathInputs()});this.toggleAddButtonIfNeeded()},toggleAddButtonIfNeeded:function(){var n=this.$(".categorySelectorList .hierarchyItemSelector"),t,i;if(!n.length){this.$(".add").show();return}t=n.length<n.first().hierarchyItemSelector().getLeafCount();i=_(n).every(function(n){var t=$(n).hierarchyItemSelector();return t.isLeaf(t.getSelectedValue())});this.$(".add").toggle(t&&i&&!this.settings.readOnly&&(!this.settings.multipleSelectedCategoryCountLimit||this.categorySelectorCount<this.settings.multipleSelectedCategoryCountLimit))},toggleCategories:function(n){var t=[],i;_(n).each(function(n){var i=!1;_(this.$(".categorySelectorList .hierarchyItemSelector")).each(function(t){var r=$(t).hierarchyItemSelector();r.getSelectedValue()==n&&(r.unselectItem(n),i=!0)});i||t.push(n)});i=this;_(t).each(function(n){var t=!1;_(this.$(".categorySelectorList .hierarchyItemSelector")).each(function(i){if(!t){var r=$(i).hierarchyItemSelector(),u=r.getSelectedValue();(_.isUndefined(u)||!r.isLeaf(u))&&(r.selectItem(n),t=!0)}});t||i.addNewCategorySelector().selectItem(n)})},removeCategorySelector:function(n){n.prev("a.remove").prev("hr").remove();n.prev("a.remove").remove();n.remove();this.categorySelectorCount--;this.renderSelectedCategories();this.toggleAddButtonIfNeeded()}})