jQuery(function(c){var r="?option=com_ajax&format=raw&plugin=nrframework&task=ConditionBuilder";function s(e,t,o){c.ajax({url:system_url+r+"&subtask="+e+"&"+token+"=1",data:t,success:function(e){o(e),c(".cb").find("select").chosen({disable_search_threshold:10}).end().find(".hasPopover").popover({html:!0,trigger:"hover focus",container:"body"})},error:function(e,t,o){alert(o)}})}system_url=c(".cb").attr("data-root"),token=c(".cb").attr("data-token"),c(document).on("click",".addCondition",function(e){e.preventDefault();var t=c(".cb");$element=c(e.target).closest(".cb-item"),$controlGroup=$element.closest(".cb-group"),$controlGroup.length?(groupKey=parseInt($controlGroup.attr("data-key")),conditionKey=parseInt($controlGroup.attr("data-max-index"))+1):(groupKey=parseInt(t.attr("data-max-index"))+1,conditionKey=0),function(t,e,o,r){var n=0==t.closest(".cb-group").length,a={controlgroup:e,groupKey:o,conditionKey:r,conditionsList:c(".cb").attr("data-conditionslist")};s("add",a,function(e){n?(c("<div/>").addClass("cb-group").attr("data-key",a.groupKey).attr("data-max-index",0).appendTo(".cb-items").html(e),c(".cb").attr("data-max-index",a.groupKey)):(t.after(e),t.closest(".cb-group").attr("data-max-index",r))})}($element,t.data("control-group"),groupKey,conditionKey)}),c(document).on("click",".removeCondition",function(e){e.preventDefault(),function(e){if(1==c(".cb-item").length)return alert("You can't remove the last item");$group=e.closest(".cb-group"),e.remove(),0==$group.children().length&&$group.remove()}(c(e.target).closest(".cb-item"))}),c(document).on("change",".condition_selector",function(e){e.preventDefault();var t=c(e.target).closest(".cb-item");condition_name=c(this).val(),function(t,o){var e=t.closest(".cb");groupKey=parseInt(t.closest(".cb-group").attr("data-key")),conditionKey=parseInt(t.closest(".cb-item").attr("data-key")),options={controlgroup:e.attr("data-control-group")+"["+groupKey+"]["+conditionKey+"]",name:o},s("options",options,function(e){t.find(".cb-item-content").html(e),c(document).trigger("afterConditionSettings",[t,o])})}(t,condition_name)}),c(document).on("afterConditionSettings",function(e,t,o){!function(e,t){var o=system_url.replace("/administrator","");switch(e){case"usergroup":case"menu":case"category":case"k2category":NRHelper.loadStyleSheet(o+"/media/plg_system_nrframework/css/treeselect.css"),NRHelper.loadScript(o+"/media/plg_system_nrframework/js/treeselect.js",function(){NRTreeselect.init(t.get(0))});break;case"date":NRHelper.loadStyleSheet(o+"/media/system/css/fields/calendar.css"),NRHelper.loadScript(o+"/media/system/js/fields/calendar-locales/en.js"),NRHelper.loadScript(o+"/media/system/js/fields/calendar-locales/date/gregorian/date-helper.min.js"),NRHelper.loadScript(o+"/media/system/js/fields/calendar.min.js",function(){var e=t.get(0).querySelectorAll(".field-calendar");for(i=0;i<e.length;i++)JoomlaCalendar.init(e[i])});break;case"time":NRHelper.loadStyleSheet(o+"/media/plg_system_nrframework/css/jquery-clockpicker.min.css"),NRHelper.loadScript(o+"/media/plg_system_nrframework/js/jquery-clockpicker.min.js",function(){t.find(".clockpicker").clockpicker()})}"date"!=e&&c(document).trigger("subform-row-add")}(o,t)})});
