ACMS.Dispatch.Admin=function(context){var Admin=arguments.callee;if(typeof Config==="undefined")var Config=ACMS.Config;if("config_unit"==ACMS.Config.admin)Admin.Configunit(context);$("input#checkAll").change(function(){$('input[type=checkbox][name="checks[]"]:not(:disabled):visible').prop("checked",this.checked)});ACMS.Dispatch.Utility.unloadAlert(context);$(".adminTable",context).not(".acms-admin-table-admin-edit").each(function(){var $tr=$("tbody > tr",this);var $theadtd=$("thead td",this);$theadtd.hover(function(){$(this).addClass("hover")},
function(){$(this).removeClass("hover")});$tr.click(function(event){if($(event.target).find("td").andSelf().filter("td").size()){var $checkbox=$(":checkbox:checked",this);if($checkbox.size())$checkbox.prop("checked",false);else $('input[name="checks[]"]',this).not(":disabled").prop("checked","checked")}})});var $media=$("#js-media_drop_area",context);if($media.size())Admin._media($media.get(0));$(".js-incremental_search",context).each(function(){Admin.acmsIncrementalSearch(this,$(".js-incremental_search_box",
context))});$(".js-acms_admin_tabs",context).each(function(){ACMS.Dispatch.acmsAdminTabs(this)});$(".js-acms-tab-select",context).each(function(){Admin.acmsSelectTabs(this)});$(".js-acms-dropdown-toggle",context).each(function(){Admin.acmsDropdown(this)});$(".js-acms-color-picker",context).each(function(){Admin.acmsColorPicker(this)});$("table.js-admin_sortable tbody",context).each(function(){$(".sorthandle .arrowHandle",this).show();$(this).sortable({handle:".sorthandle",axis:"y",zIndex:999,opacity:0.6})});
if($(".stay").length){var $navi=$(".stay").offset().top-$(".acms-admin-navbar").height();var $naviBar=$("#sidebar").height()-$(".acms-admin-navbar").height()-100;if($navi>$naviBar)$("#sidebar").scrollTop($navi)}var $map=$(".js-map-editable",context);if($map.size()){var region="";if(ACMS.Config.s2dRegion)region="&region="+ACMS.Config.s2dRegion;ACMS.Library.googleLoadProxy("maps","3",{callback:function(){$map.each(function(){ACMS.Dispatch.Edit.map(this)})}})}var $yolp=$(".js-yolp-editable",context);
if($yolp.size())ACMS.Library.yahooLoadProxy({callback:function(){$map.each(function(){ACMS.Dispatch.Edit.yolp(this)})}});$("table#js-arg_reference .js-arg_reference_trigger",context).click(function(){var self=arguments.callee,$trigger=$(this),field=$trigger.attr("name"),url;if(1&field!="bid"&field!="cid"&field!="ccd"&field!="eid"&field!="uid"&field!="ucd")return false;$().dialog();$trigger.attr("disabled","disabled");if("undefined"==typeof self.$popup)self.$popup={};if(_.contains(["bid","uid","cid",
"eid"],field))url="ajax/arg/"+field+"-reference.html";else url="ajax/arg/reference.html";if(0===$("#reference-"+field,context).length){var url=ACMS.Library.acmsLink({tpl:url,Query:{scope:field,hash:Math.random()}},true);$.get(url,function(html){var code='                    <div class="acms-admin-modal out">                        <div class="acms-admin-modal-dialog">                            <div class="acms-admin-modal-content">                                <div class="acms-admin-modal-header">                                    <i class="acms-admin-modal-hide acms-admin-icon-delete"></i>                                    <h3>ID\u53c2\u7167</h3>                                </div>                                <div class="acms-admin-modal-body">                                    <div class="acms-admin-padding-small clearfix"></div>                                </div>                            </div>                        </div>                    </div>';
var $modalBox=$($.parseHTML(code)).appendTo("body"),$raw=$($.parseHTML(html)),$input=$trigger.closest(".js-arg_guidance").find(".js-arg_guidance_edit"),$labelBox=$trigger.closest(".js-arg_guidance").find(".js-arg_guidance_label"),$backdrop=$($.parseHTML('<div class="acms-admin-modal-backdrop"></div>')).hide().appendTo("body"),$labelDummy=$(".js-arg_reference_dummy");if($modalBox.length){$("body").css("overflow","hidden");$modalBox.find(".acms-admin-modal-body > .acms-admin-padding-small").append($raw);
setTimeout(function(){$modalBox.show();$backdrop.show();$modalBox.removeClass("out").delay(200).queue(function(){$(this).addClass("in").delay(500).queue(function(){$(this).addClass("display").removeClass("in")}).dequeue()})},200);var zIndex=$(".acms-admin-modal-backdrop").length*1E5;$backdrop.css("z-index",zIndex);$modalBox.css("z-index",zIndex+1)}Config.postIncludeMethod="replace";Config.postIncludeEffect="";Config.postIncludeEffectSpeed=0;ACMS.Dispatch.Postinclude.submit($modalBox.find(".js-ajax_load"));
$(".js-ajax_load_link_delegate",$modalBox).on("click",".js-ajax_load_link a",function(){var href=$(this).attr("href"),query="?"+href.split("?")[1],send=ACMS.Library.getParameterByName("send",query);if(!send)href+="&send=ajax";$.get(href,function(html){$modalBox.find(".js-ajax_load_replace").html(html)});event.preventDefault();return false});var closeFn=function(){$("body").css("overflow","");$backdrop.fadeOut(150,function(){$backdrop.remove()});$modalBox.removeClass("display").addClass("out");setTimeout(function(){$modalBox.remove()},
500);return false};$(".acms-admin-modal-hide").bind("click",closeFn);$modalBox.click(function(event){var click=event.target;if($(click).hasClass("acms-admin-modal"))closeFn()});$(ACMS.Config.acmsTabsMark,$modalBox).each(function(){ACMS.Dispatch.acmsTabs(this)});$(".js-ajax_load_link_delegate",$modalBox).on("click",".js-arg_reference_anchor",function(){var $label=$labelDummy.clone().show().css("display","inline-block"),ids=$input.val().split(","),id=String($(this).data("id")),label=$(this).data("label");
if(!_.include(ids,id)){$label.find("span").text(label);$label.attr("data-arg",id);Admin.argReferenceRemove($label);if($input.data("multi")==="on"){$labelBox.append($label[0]);$labelBox.append(" ");if(id)ids.push(id)}else{$labelBox.html($label[0]);if(id)ids=Array(id)}ids=_.uniq(ids);ids=$.grep(ids,function(e){return e});$input.val(ids.join())}closeFn();return false})})}$trigger.removeAttr("disabled");return false});$(".js-arg_reference_remove",context).each(function(){Admin.argReferenceRemove(this)});
$("#js-arg_guidance_name",context).each(function(){var tag=this.tagName.toLowerCase();switch(tag){case "select":$(this).change(function(){var module=$(this).val();if(module!==""){var guide=ACMS.Config.Admin.argGuidance[module];var axisGuide=ACMS.Config.Admin.axisGuidance[module];var multiArgs=ACMS.Config.Admin.multiArgGuidance[module];if(typeof guide!=="undefined"){$("input:text, input:checkbox, .js-arg_reference_trigger",$('[id^="js-arg_guidance_"]')).attr("disabled","disabled");$('tr[id^="js-arg_guidance_"]').css("color",
"silver");$.each(guide,function(){$('[name^="'+this+'"]').removeAttr("disabled");$("tr#js-arg_guidance_"+this).css("color","black")})}else{$("input:text, input:checkbox",$('[id^="js-arg_guidance_"]')).removeAttr("disabled");$('tr[id^="js-arg_guidance_"]').css("color","black")}if(typeof axisGuide!=="undefined"){$("input:text, input:checkbox, select",$('[id^="js-axis_guidance_"]')).attr("disabled","disabled");$('tr[id^="js-axis_guidance_"]').css("color","silver");$.each(axisGuide,function(){$('[name^="'+
this+'"]').removeAttr("disabled");$("tr#js-axis_guidance_"+this).css("color","black")})}else{$("input:text, input:checkbox, select",$('[id^="js-axis_guidance_"]')).removeAttr("disabled");$('tr[id^="js-axis_guidance_"]').css("color","black")}$("input:text",$('[id^="js-arg_guidance_"]')).removeAttr("data-multi");if(typeof multiArgs!=="undefined")$.each(multiArgs,function(){$('input:text[name^="'+this+'"]').attr("data-multi","on")})}});$(this).change();break;case "td":var module=$(this).text();var guide=
ACMS.Config.Admin.argGuidance[module];var axisGuide=ACMS.Config.Admin.axisGuidance[module];$('tr[id^="js-arg_guidance_"]').css("color","silver");$('tr[id^="js-axis_guidance_"]').css("color","silver");$.each(guide,function(){$("tr#js-arg_guidance_"+this).css("color","black")});$.each(axisGuide,function(){$("tr#js-axis_guidance_"+this).css("color","black")});break}});$(".js-arg_reference_toggle ~ .argEdit",context).hide();$(".js-arg_reference_toggle",context).click(function(){var $item=$(this).closest(".js-arg_guidance");
var $text=$item.find(".argEdit");var $label=$item.find(".argLabel");$text.toggle();$label.toggle();return false});$(".switching-function-btn:not(:checked)",context).each(function(){$(this).closest("table").next("div").hide()});$(".switching-function-btn",context).click(function(){var box=$(this).closest("table").next("div");if($(this).prop("checked")===true)box.slideDown("fast");else box.slideUp("fast")});$(".js-acms_column_add_type",context).each(function(){if($(this).val()!==""){var attr=$(this).attr("name");
$('input[type=text][name="'+attr+'"]').attr("disabled","disabled").hide()}});$(".js-acms_column_add_type",context).change(function(){var attr=$(this).attr("name");if($(this).val()!=="")$('input[type=text][name="'+attr+'"]').attr("disabled","disabled").hide();else $('input[type=text][name="'+attr+'"]').removeAttr("disabled").show()});$(".js-rule_term_type").bind("change",function(){var val=$(this).val();if(val.length>0)$(this).siblings(".js-radio_type").val("");if(val!=="fix"){$(".js-rule_term_start_date").val("").prop("disabled",
true);$(".js-rule_term_end_date").val("").prop("disabled",true)}else{$(".js-rule_term_start_date").prop("disabled",false);$(".js-rule_term_end_date").prop("disabled",false)}}).change();$(".js-load_hide_box").hide();var browser=ACMS.Dispatch.Utility.browser();$("#js-select_theme_action").bind(browser.ltIE8?"click":"change",function(){var key=$(this).children(":selected").attr("id");$(".tplYamlTable").hide();$(".js-theme_"+key).show()});$("#js-index_list_tabs").each(function(){var $self=$(this).show(),
$items=$self.find("a"),$tabs=$(".indexListCategory");$tabs.not(":first").hide();$items.each(function(i){$(this).click(function(){$items.removeClass("selected");$(this).addClass("selected");$tabs.hide();$($tabs.get(i)).show();$.cookie("lastClickedIndex",i);return false})});if($.cookie("lastClickedIndex")!=null)$($items.get($.cookie("lastClickedIndex"))).click();else $items.first().click()});$("#js-entry_index_category_filter_dup").val($("#js-entry_index_category_filter").val());$("#js-entry_index_category_filter").change(function(){$("#js-entry_index_category_filter_dup").val($(this).val())});
$(".formDisable").find(":input").attr("disabled","disabled");var $inpSubmit=$(".js-submitlock",context);if($inpSubmit.size())$inpSubmit.click(function(){$(this).bind("click",function(){alert(ACMS.i18n.submitlock.message1);return false});return true});$(".js-admin_action_toggle").click(function(){if($.cookie("acms_config_admin_action_box")=="on"){$("#js-admin_action_box").fadeOut(400);$.cookie("acms_config_admin_action_box","",{path:"/"})}else{$("#js-admin_action_box").fadeIn(400);$.cookie("acms_config_admin_action_box",
"on",{path:"/"})}return false});$(".js-acms_entry_index_duplicate").click(function(){var $self=$(this);var $row=$self.parents("tr");var $id=$('[name^="checks"]',$row).val();var $form=document.createElement("form");var $checks=document.createElement("input");var $submit=document.createElement("input");$checks.name="checks[]";$checks.value=$id;$checks.type="hidden";$submit.name="ACMS_POST_Entry_Index_Duplicate";$submit.value="duplicate";$submit.type="hidden";$form.method="post";$form.appendChild($checks);
$form.appendChild($submit);document.body.appendChild($form);$form.submit();return false});$(".js-acms_entry_index_delete").click(function(){if(confirm(ACMS.i18n.edit.message1)){var $self=$(this);var $row=$self.parents("tr");var $id=$('[name^="checks"]',$row).val();var $form=document.createElement("form");var $checks=document.createElement("input");var $submit=document.createElement("input");$checks.name="checks[]";$checks.value=$id;$checks.type="hidden";$submit.name="ACMS_POST_Entry_Index_Trash";
$submit.value="delete";$submit.type="hidden";$form.method="post";$form.appendChild($checks);$form.appendChild($submit);document.body.appendChild($form);$form.submit()}return false});$(".js-acms_entry_index_trash").click(function(){if(confirm(ACMS.i18n.edit.message2)){var $self=$(this);var $row=$self.parents("tr");var $id=$('[name^="checks"]',$row).val();var $form=document.createElement("form");var $checks=document.createElement("input");var $submit=document.createElement("input");$checks.name="checks[]";
$checks.value=$id;$checks.type="hidden";$submit.name="ACMS_POST_Entry_Index_TrashRestore";$submit.value="restore";$submit.type="hidden";$form.method="post";$form.appendChild($checks);$form.appendChild($submit);document.body.appendChild($form);$form.submit()}return false});if($(".js-acms_fix_marker").length){var $offset=$(".js-acms_fix_marker").offset();var $target=$(".js-acms_fix_target");var $next=$target.next();var $bar=$target.height();var $top=$next.css("margin-top");var x=767;$(window).scroll(function(){var windowWidth=
window.innerWidth||document.documentElement.clientWidth||0;if(windowWidth>x)if($(window).scrollTop()>$offset.top-$bar-18){$target.addClass("fixed");$next.css("margin-top",$bar+14)}else if($(window).scrollTop()<$offset.top){$target.removeClass("fixed");$next.css("margin-top",$top)}})}$(Config.adminTableSortableMark,context).each(function(){ACMS.Dispatch.Admin.adminTableSortable(this)});$(Config.fieldgroupSortableMarkForm,context).each(function(){ACMS.Dispatch.Admin.fieldgroupSortableForm(this)});$(Config.innerFieldgroupListMark,
context).each(function(){ACMS.Dispatch.Admin.innerFieldgroupList(this)});if(window.name==="popup_setting_result"||window.name==="popup_setting"){$("#acms-admin-main").css({"padding-left":"20px","padding-top":"5px"});$(".acms_fix_bg").css({"padding-left":0,top:0,left:"10px"});$(".acms-admin-navbar-admin, #nav").hide();if(window.name==="popup_setting_result"){if(Config.popupSettingConf.autoreload)window.opener.location.reload();if(Config.popupSettingConf.autoclose)window.close()}$("form",context).bind("submit",
function(){if(window.name==="popup_setting")window.name="popup_setting_result"})}};
ACMS.Dispatch.Admin.acmsIncrementalSearch=function(elm,$input){var $item=$(".search_element",elm),placeholder=$input.attr("placeholder");$input.keyup(function(){var search=this.value.split(" ");if(0||search.length===1&&search[0]===placeholder||search.length===2&&search[0]+" "+search[1]===placeholder)return false;for(var i=0;i<$item.length;i++){var $clone=$($item[i]).clone(false);$clone.find(".except").remove();var itemName=$clone.text();if(itemName.match(new RegExp(search[0],"i"))||!search[0]){$($item[i]).show();
if(search.length>1)for(var j=1;j<search.length;j++)if(!itemName.match(new RegExp(search[j],"i")))$($item[i]).hide()}else $($item[i]).hide()}return false}).keyup()};ACMS.Dispatch.Admin.acmsSelectTabs=function(elm){var $select=$(".js-acms-tab-select-value",elm);var $expr=$(".js-acms-tab-select-panel",elm);$select.change(function(){$expr.each(function(){$(this).removeClass("js-acms-tab-select-active")});var id="#"+$(this).val();$(id,elm).addClass("js-acms-tab-select-active")})};
ACMS.Dispatch.Admin.acmsDropdown=function(elm){$(".js-acms-dropdown-btn",elm).click(function(){var $open=$(".js-acms-dropdown-menu",elm).css("display");$(".js-acms-dropdown-menu",document).hide();if($open==="block")$(".js-acms-dropdown-menu",elm).hide();else $(".js-acms-dropdown-menu",elm).show();$(document).unbind("click.dropdonw");$(document).bind("click.dropdonw",function(){$(".js-acms-dropdown-menu",document).hide();$(document).unbind("click.dropdonw")});return false})};
ACMS.Dispatch.Admin.acmsColorPicker=function(elm){var settings={palette:["ffffff","ffccc9","ffce93","fffc9e","ffffc7","9aff99","96fffb","cdffff","cbcefb","cfcfcf","fd6864","fe996b","fffe65","fcff2f","67fd9a","38fff8","68fdff","9698ed","c0c0c0","fe0000","f8a102","ffcc67","f8ff00","34ff34","68cbd0","34cdf9","6665cd","9b9b9b","cb0000","f56b00","ffcb2f","ffc702","32cb00","00d2cb","3166ff","6434fc","656565","9a0000","ce6301","cd9934","999903","009901","329a9d","3531ff","6200c9","343434","680100","963400",
"986536","646809","036400","34696d","00009b","303498","000000","330001","643403","663234","343300","013300","003532","010066","340096"]},$target=null,$bgcolor=null,$submit=$(".js-acms-color-picker-submit",elm);var i=0,iz=settings.palette.length,color,select='<div style="background-color:#FFF;">',$pallete;for(;i<iz;i++){color=settings.palette[i];select+='<a style="display:block; float:left; width:30px; height:30px; margin:5px; border:solid 1px #444; cursor:pointer; background-color: #'+color+'">&nbsp;</a>'}select+=
"</div>";$pallete=$($.parseHTML(select));$("a",$pallete).bind("click",function(){var $self=$(this);var hex_rgb=$self.css("background-color"),r,g,b,hex_color;if(hex_rgb.match(/^rgb\((\d+),\s?(\d+),\s?(\d+)\)$/)){r=parseInt(RegExp.$1);g=parseInt(RegExp.$2);b=parseInt(RegExp.$3);if(r!==void 0){r=("00"+r.toString(16)).slice(-2).toUpperCase();g=("00"+g.toString(16)).slice(-2).toUpperCase();b=("00"+b.toString(16)).slice(-2).toUpperCase();hex_color="#"+r+g+b}}if(r===void 0)hex_color=hex_rgb.toUpperCase();
$bgcolor.css("background-color",hex_rgb);$target.val(hex_color);$pallete.dialog("close")});$submit.bind("click",function(){var $self=$(this);$target=$($self.data("target"));$bgcolor=$($self.data("bgcolor"));$pallete.dialog({title:"\u8272\u3092\u9078\u629e",close:function(){$pallete.hide()}});$win_w=$(window).width();$pallete.dialog("option",{width:$win_w>320?430:280});$pallete.dialog("open");$pallete.dialog("widget").position({of:$submit,my:"left bottom",at:"right top",collision:"none"});return false})};
ACMS.Dispatch.Admin.argReferenceRemove=function(elm){$(elm).click(function(){var $self=$(this);var $input=$self.closest(".js-arg_guidance").find(".argEdit");$self.fadeOut(function(){var arg=String($self.data("arg"));var ids=$input.val().split(",");ids=_.reject(ids,function(id){return id===arg});$input.val(ids.join());$(this).remove()});return false})};
ACMS.Dispatch.Admin.innerFieldgroupList=function(elm){var Config=ACMS.Config;var $groupList=$(elm);var $insert=$groupList.find(Config.innerFieldgroupListInsertMark);var $anchor=$groupList.find(Config.innerFieldgroupListTemplateMask);var $input=$groupList.find(Config.innerFieldgroupListInputMask);$anchor.find(":input").attr("disabled","");var $template=$anchor.clone();$anchor.find(":input").attr("disabled","disabled");$anchor.hide();number($groupList);if($insert.size()&&$anchor.size())$insert.unbind("click").click(function(){var $clone=
$template.clone();$clone.removeClass(Config.innerFieldgroupListTemplateMask.substr(1));$clone.find(":input").not(Config.innerFieldgroupListDeleteMask).val("");$clone.show();$clone.find(Config.innerFieldgroupListDeleteMask).click(function(){$(this).parents(Config.innerFieldgroupListItemMask).remove();number($(this).parents(Config.innerFieldgroupListMark));return false});$anchor.before($clone);number($(this).parents(Config.innerFieldgroupListMark));ACMS.Dispatch.Admin($clone);return false});$groupList.find(Config.innerFieldgroupListDeleteMask).click(function(){$(this).parents(Config.innerFieldgroupListItemMask).remove();
number($(this).parents(Config.innerFieldgroupListMark));return false});var n=0;$groupList.find(Config.fieldgroupListItemMark).each(function(){if("none"==$(this).css("display"))return true;n++});if(!n){var $clone=$template.clone();$clone.removeClass(Config.innerFieldgroupListTemplateMask.substr(1));$(':input[name$="]"]',$clone).each(function(){this.name=this.name.replace(/\[\d*\]$/,"[0]")});if($anchor.hasClass("new-box"))$anchor.before($clone);ACMS.Dispatch.Admin($clone)}function number($groupList){var $rows=
$groupList.find(Config.innerFieldgroupListItemMask+":visible");var n=0;$rows.each(function(){$(':input[name$="]"]',this).each(function(){this.name=n+"-"+this.name});n++});n=0;$rows.each(function(){$(':input[name$="]"]',this).each(function(){top_num=this.name.match(/\[\d*\]/);this.name=this.name.replace(/\[\d*\]\[\d*\]/,top_num+"["+n+"]")});n++});n=0;$rows.each(function(){var regex=new RegExp("^"+n+"-");$(':input[name$="]"]',this).each(function(){this.name=this.name.replace(regex,"")});n++})}};
ACMS.Dispatch.Admin.adminTableSortable=function(elm){if($(elm).data("sort-enable")!=="on"){$(".item-handle",elm).hide();return false}var $adminTable=$("tbody",elm),$submitName=$(elm).data("sort-submit"),$targetForm=$(elm).parents("form");$entryOrder=$(elm).data("sort-order"),$isException=$(elm).hasClass("exceptionSort"),$firstSortNum=$("tbody > tr:first",elm).find(".sort-number").val(),$anchor=$(elm).find(".item-template"),$insert=$(elm).find(".item-insert"),$template=$anchor.clone(),$parentList=
$(elm).find("[name^=navigation_parent]").eq(1).clone();$anchor.find(":input").attr("disabled","disabled");$anchor.hide();$insert.bind("click",function(){addItem()});$adminTable.sortable({activate:function(event,ui){var level=ui.item.data("sort-level");sortableItem(ui,level)},deactivate:function(event,ui){$("tr",elm).removeClass("ui-state-disabled")},update:function(event,ui){var level=ui.item.data("sort-level");sortnumber(level)},handle:".item-handle",items:"tr:not(.ui-state-disabled)"});$adminTable.find(".item-delete").click(function(){var $item=
$(this).parents(".sort-item");deleteItem($item)});function addItem(){var $clone=$template.clone(),$list=$parentList.clone().val(""),count=$(elm).find("[data-sort-level=level-0-0]").length,all=$(elm).find(".sort-item").length,txt=$clone.html();$clone.html(txt.replace(/--seq--/g,all));$clone.find(".parent-select").replaceWith($list.get(0));var $sortSelect=$clone.find(".sort-select");for(var i=1;i<=count;i++){var $option=$("<option>").val(i).text(i);if(i===count)$option.prop("selected",true);$sortSelect.append($option)}$clone.find(".item-delete").click(function(){deleteItem($clone)});
$clone.addClass("sort-item").show();$anchor.before($clone);$adminTable.sortable("refresh")}function deleteItem($item){var msg=ACMS.Config.fieldgroupSortableItemDeleteMessage;if(!msg.length||confirm(msg)){$item.removeClass("sort-item").hide();$item.find("input:not(:checkbox)").val("");$adminTable.sortable("refresh")}}function sortableItem(ui,level){$("tr",elm).each(function(){if($(this).data("sort-level")===level)$(this).removeClass("ui-state-disabled");else $(this).addClass("ui-state-disabled")});
$adminTable.sortable({items:"tr:not(.ui-state-disabled)"});$adminTable.sortable("refresh")}function sortnumber(level){var number=1;var increment=true;if($entryOrder){if($entryOrder==="sort-asc")increment=true;else if($entryOrder==="sort-desc")increment=false;number=parseInt($firstSortNum)}$("tr",elm).each(function(){if($(this).data("sort-level")===level){var selctName=$(this).data("sort-name");$("[name^='"+selctName+"']",this).val(number);if(!$("[name^='"+selctName+"']",this).val()){var $option=$("<option>").val(number).text(number);
$("[name^='"+selctName+"']",this).append($option).val(number)}$("[name^=checks]",this).attr("checked",true);if(increment)number++;else number--}});if($isException)$adminTable.sortable("cancel");$("<input />").attr("type","hidden").attr("name",$submitName).attr("value","save").appendTo($targetForm);$targetForm.submit()}};
ACMS.Dispatch.Admin.fieldgroupSortableForm=function(elm){var Config=ACMS.Config;var $sortable=$(elm);var $insert=$sortable.find(Config.fieldgroupSortableItemInsertMark);var $anchor=$sortable.find(Config.fieldgroupSortableItemTemplateMark);if($insert.size()&&$anchor.size()){var $template=$anchor.clone();$anchor.find(":input").attr("disabled","disabled");$anchor.hide();number($sortable);$insert.click(function(){var $clone=$template.clone();var $addFormUnitTypeLabel=$("#formUnitType option:selected").text();
var $addFormUnitTypeValue=$("#formUnitType option:selected").val();if($addFormUnitTypeValue&&$addFormUnitTypeLabel&&$clone.find(".form-label")){$clone.find(".form-label").text($addFormUnitTypeLabel);$clone.find('input[name*="formbuild_type"]').val($addFormUnitTypeValue);switch($addFormUnitTypeValue){case "text":case "textarea":$clone.find(".select-value-box").hide();break;case "radio":case "select":case "multiSelect":case "checkbox":$clone.find(".textTypeOnly").hide();break;default:$clone.find(".inputFormBody").hide();
break}}$clone.removeClass(Config.fieldgroupSortableItemTemplateMark.substr(1));$clone.show();$clone.find(Config.fieldgroupSortableItemDeleteMark).click(function(){var msg=Config.fieldgroupSortableItemDeleteMessage;if(!msg.length||confirm(msg)){detouch($sortable);$(this).parents(Config.fieldgroupSortableItemMark).remove();number($sortable);touch($sortable)}return false});$anchor.before($clone);number($sortable);$clone.find(Config.fieldgroupSortableItemHandleMark).css("cursor","pointer");ACMS.Dispatch($clone);
return false});var n=0;$sortable.find(Config.fieldgroupSortableItemMark).each(function(){var $block=$(this);if($block.find(".form-type"))switch($block.find(".form-type").val()){case "text":case "textarea":$block.find(".select-value-box").hide();break;case "radio":case "select":case "multiSelect":case "checkbox":$block.find(".textTypeOnly").hide();break;default:$block.find(".inputFormBody").hide();break}if("none"==$(this).css("display"))return true;n++});if(!n){var $clone=$template.clone();$clone.removeClass(Config.fieldgroupSortableItemTemplateMark.substr(1));
$(':input[name$="]"]',$clone).each(function(){this.name=this.name.replace(/\[\d*\]/,"[0]")});ACMS.Dispatch($clone);$anchor.before($clone)}$sortable.find(Config.fieldgroupSortableItemDeleteMark).click(function(){var msg=Config.fieldgroupSortableItemDeleteMessage;if(!msg.length||confirm(msg)){detouch($sortable);$(this).parents(Config.fieldgroupSortableItemMark).remove();number($sortable);touch($sortable)}return false})}$sortable.find(Config.fieldgroupSortableItemHandleMark).css("cursor","pointer");
$sortable.sortable({items:Config.fieldgroupSortableItemMark,handle:Config.fieldgroupSortableItemHandleMark,axis:"y",start:function(event,ui){detouch($sortable)},stop:function(event,ui){number($sortable);touch($sortable);ACMS.Dispatch($sortable)}});function touch(context){$.each(Config.emoArray.concat({mark:Config.emoMark,toolbar:Config.emoToolbar,config:Config.emoConfig}),function(){Config.emoToolbar=this.toolbar;Config.emoConfig=this.config;$(this.mark,context).each(function(){ACMS.Dispatch.emoditor(this)})})}
function detouch(context){$("textarea",context).each(function(){var editor=$(this).data("emoditor");if(editor)editor.destroy();$(this).removeData("emoditor")});return context}function number($sortable){var $rows=$sortable.find(Config.fieldgroupSortableItemMark).not(Config.fieldgroupSortableItemTemplateMark);var n=0;$rows.each(function(){$(':input[name$="]"]',this).each(function(){this.name=n+"-"+this.name});n++});n=0;$rows.each(function(){$(':input[name$="]"]',this).each(function(){this.name=this.name.replace(/\[\d*\]/,
"["+n+"]")});n++});n=0;$rows.each(function(){var regex=new RegExp("^"+n+"-");$(':input[name$="]"]',this).each(function(){this.name=this.name.replace(regex,"")});n++})}};
