1 line
No EOL
11 KiB
JavaScript
1 line
No EOL
11 KiB
JavaScript
function ProcessTemplateAsmSelect(){function setupRows(){var $inputfield=$("#wrap_fieldgroup_fields");var $item=$inputfield.find(".asmListItem").eq(0);var $lastItem=null;var lastItemWidth=0;var total=0;var numRows=0;do{$item.removeClass("rowItem rowStart rowStop rowError");var w=parseInt($item.find(".columnWidth").text());if(w===100){if(total>0&&total<100&&lastItemWidth>0&&lastItemWidth<100){$lastItem.addClass("rowError");if(!$lastItem.hasClass("rowStart"))$lastItem.addClass("rowStop")}total=0}else{if(!total){$item.addClass("rowStart");numRows++}$item.addClass("rowItem");if(total+w>100){if($lastItem&&lastItemWidth<100){if($lastItem.hasClass("rowStart")){$lastItem.addClass("rowError")}else{$lastItem.addClass("rowStop rowError")}}$item.addClass("rowStart");numRows++;total=w}else if(total+w==100){$item.addClass("rowStop");total=0}else{total+=w}}$lastItem=$item;lastItemWidth=w;$item=$item.next(".asmListItem")}while($item.length);if($lastItem.length&&lastItemWidth<100){$lastItem.addClass("rowStop");if(total>0&&total<100){$lastItem.addClass("rowError")}else{$lastItem.removeClass("rowError")}}return numRows}function setupColumnWidth(){var $percentElement=null;var currentPct=0;var lastPageX=0;var lastPageY=0;var mousingActive=false;var isDblClick=false;var snapWithin=9;var snapWidth=0;function asmListItem($item){if(!$item.hasClass("asmListItem"))$item=$item.closest(".asmListItem");return $item}function columnWidthItem($item){if($item.hasClass("columnWidth"))return $item;return $item.find(".columnWidth")}function getColumnWidth($item){$item=columnWidthItem($item);return parseInt($item.text())}function getSnapWidth($item){$item=asmListItem($item);var rowWidth=getRowWidth($item);var itemWidth=getColumnWidth($item);var snap;if(rowWidth==100){snap=itemWidth}else{snap=100-(rowWidth-itemWidth)}return snap}function getRowStartItem($item){$item=asmListItem($item);if(!$item.hasClass("rowItem")||$item.hasClass("rowStart"))return $item;var $prevItem=$item;do{$prevItem=$prevItem.prev(".rowItem")}while($prevItem.length&&!$prevItem.hasClass("rowStart"));return $prevItem.length?$prevItem:$item}function getRowStopItem($item){$item=asmListItem($item);if(!item.hasClass("rowItem")||$item.hasClass("rowStop"))return $item;var $nextItem=$item;do{$nextItem=$nextItem.next(".rowItem")}while($nextItem.length&&!$nextItem.hasClass("rowStop"));return $nextItem.length?$nextItem:$item}function getRowWidth($item){if(!$item.hasClass("rowItem"))return 100;$item=getRowStartItem($item);var total=getColumnWidth($item);var $nextItem=$item;var w=0;do{$nextItem=$nextItem.next(".rowItem");if(!$nextItem.length||$nextItem.hasClass("rowStart"))break;w=getColumnWidth($nextItem);if(total+w>100)break;total+=w}while(total<100&&!$nextItem.hasClass("rowStop"));return total}function setColumnWidth($item,columnWidth){var $parent;if($item.hasClass("columnWidth")){$parent=$item.closest(".asmListItem")}else{$parent=$item;$item=$item.find(".columnWidth")}if(snapWidth>0){if(columnWidth>snapWidth&&columnWidth-snapWidth<=snapWithin){columnWidth=snapWidth}else if(columnWidth<snapWidth&&snapWidth-columnWidth<=snapWithin){columnWidth=snapWidth}}var pct=parseInt(columnWidth)+"%";$item.text(pct);var $columnWidthBar=$parent.find(".columnWidthBar");var $columnWidthBarPct=$columnWidthBar.children(".columnWidthBarPct");$columnWidthBar.css("width",columnWidth+"%");if(columnWidth>=90){$columnWidthBarPct.text("")}else{$columnWidthBarPct.text(pct)}}function saveColumnWidth($item){var columnWidth=getColumnWidth($item);var $li=$item.hasClass("asmListItem")?$item:$item.closest(".asmListItem");var url="./saveProperty";var data={id:$("#Inputfield_id").val(),property:"columnWidth",columnWidth:columnWidth,field:parseInt($li.find(".columnWidth").attr("data-field"))};var $csrf=$("input._post_token");data[$csrf.attr("name")]=$csrf.val();$.post(url,data,function(result){if(result.success){if(result.value!=columnWidth)setColumnWidth($item,result.value)}},"json")}function startColumnWidthBar($item){if(!$item.hasClass("asmListItem"))$item=$item.closest(".asmListItem");if(isDblClick||!mousingActive)return;var $columnWidthBar=$item.find(".columnWidthBar");if($columnWidthBar.length)$columnWidthBar.remove();var pct=getColumnWidth($item)+"%";var $columnWidthBarPct=$("<span />").addClass("columnWidthBarPct").text(pct);$columnWidthBar=$("<div />").addClass("columnWidthBar").append($columnWidthBarPct);$columnWidthBar.appendTo($item);$columnWidthBar.css("width",pct)}function stopColumnWidthBar($item){if(!$item.hasClass("asmListItem"))$item=$item.closest(".asmListItem");var $columnWidthBar=$item.find(".columnWidthBar");if(!$columnWidthBar.length)return;$columnWidthBar.remove()}function setActive($item,active){var $list=$item.closest(".ui-sortable");if(!$item.hasClass("columnWidth"))$item=$item.find(".columnWidth");var $parent=$item.closest(".asmListItem");if(active){if(mousingActive)return;mousingActive=true;$item.addClass("columnWidthActive");$("body").addClass("columnWidthActive");$item.siblings(".fieldType, .fieldInfo").css("opacity",.3);$list.sortable("disable");snapWidth=getSnapWidth($parent);startColumnWidthBar($item)}else{if(!mousingActive)return;mousingActive=false;stopColumnWidthBar($item);snapWidth=0;$item.removeClass("columnWidthActive");$("body").removeClass("columnWidthActive");$item.siblings(".fieldType, .fieldInfo").css("opacity",1);$list.sortable("enable")}}var mouseMove=function(e){if(lastPageX&&lastPageY){var diffX=e.pageX-lastPageX;var diffY=e.pageY-lastPageY;var diff=Math.abs(diffX)>=Math.abs(diffY)?diffX:diffY*-1;if(diff===0)return;var pct=currentPct;if(diff>0&&pct<100)pct++;if(diff<0&&pct>10)pct--;if(pct!=currentPct){setColumnWidth($percentElement,pct);currentPct=pct}}lastPageX=e.pageX;lastPageY=e.pageY};var mouseUp=function(){$(document).off("mouseup",mouseUp);$(document).off("mousemove",mouseMove);saveColumnWidth($percentElement);setActive($percentElement,false);setupRows()};var mouseDown=function(e){$percentElement=$(this);if($percentElement.hasClass("columnWidthOff"))return false;setActive($percentElement,true);currentPct=getColumnWidth($percentElement);$(document).on("mouseup",mouseUp);$(document).on("mousemove",mouseMove)};var mouseOut=function(e){if(mousingActive)return;$(this).closest(".ui-sortable").sortable("enable")};var mouseOver=function(e){if(mousingActive)return;$(this).closest(".ui-sortable").sortable("disable")};var dblClick=function(e){var $t=$(this);isDblClick=true;snapWidth=getSnapWidth($t);if(snapWidth){setColumnWidth($t,snapWidth);setupRows();saveColumnWidth($t)}isDblClick=false};var $inputfield=$("#wrap_fieldgroup_fields");var $select=$("#fieldgroup_fields");$inputfield.on("mousedown",".columnWidth",mouseDown).on("mouseover",".columnWidth",mouseOver).on("mouseout",".columnWidth",mouseOut).on("dblclick",".columnWidth",dblClick).on("asm-ready",function(){setupRows()});$select.on("change",function(e,eventData){if(typeof eventData=="undefined")return;if(typeof eventData.type=="undefined")return;if(eventData.type==="add")$inputfield.addClass("field-added");if(eventData.type!="sort")return;setupRows();var value=$(this).val();var url="./saveProperty";var data={id:$("#Inputfield_id").val(),property:"fieldgroup_fields",fieldgroup_fields:value,_fieldgroup_fields_changed:"changed"};var $csrf=$("input._post_token");data[$csrf.attr("name")]=$csrf.val();$.post(url,data,function(result){},"json")})}setupColumnWidth()}function ProcessTemplate(){function setupAccessTab(){var redirectLoginClick=function(){if($("#redirectLogin_-1:checked").length>0){$("#wrap_redirectLoginURL").slideDown()}else{$("#wrap_redirectLoginURL").hide()}};var adjustAccessFields=function(){var items=["#wrap_redirectLogin","#wrap_guestSearchable"];if($("#roles_37").is(":checked")){$("#wrap_redirectLoginURL").hide();$(items).each(function(key,value){var $item=$(value);if($item.is(".InputfieldStateCollapsed")){$item.hide()}else{$item.slideUp()}});$("input.viewRoles").prop("checked",true)}else{$(items).each(function(key,value){var $item=$(value);if($item.is(":visible"))return;$item.slideDown("fast",function(){if(!$item.is(".InputfieldStateCollapsed"))return;$item.find(".InputfieldStateToggle").trigger("click")})});redirectLoginClick()}};$("#wrap_useRoles input").on("click",function(){if($("#useRoles_1:checked").length>0){$("#wrap_redirectLogin").hide();$("#wrap_guestSearchable").hide();$("#useRolesYes").slideDown(400,function(){$(this).css("overflow","visible")});$("input.viewRoles").prop("checked",true)}else{$("#useRolesYes").slideUp();$("#accessOverrides:visible").slideUp()}});if($("#useRoles_0:checked").length>0){$("#useRolesYes").hide();$("#accessOverrides").hide()}$("#roles_37").on("click",adjustAccessFields);$("input.viewRoles:not(#roles_37)").on("click",function(){var $t=$(this);if($("#roles_37").is(":checked"))return false;return true});var editRolesClick=function(){var $editRoles=$("#roles_editor input.editRoles");var numChecked=0;$editRoles.each(function(){var $t=$(this);if($t.is(":disabled"))return false;var $createRoles=$("input.createRoles[value="+$t.attr("value")+"]");if($t.is(":checked")){numChecked++;$createRoles.prop("disabled",false)}else{$createRoles.prop("checked",false).prop("disabled",true)}});if(numChecked){$("#accessOverrides").slideDown()}else{$("#accessOverrides").hide()}return true};var editOrAddClick=function(){var numChecked=0;$("#roles_editor input.editRoles").each(function(){if(!$(this).is(":disabled")&&$(this).is(":checked"))numChecked++});$("#roles_editor input.addRoles").each(function(){if(!$(this).is(":disabled")&&$(this).is(":checked"))numChecked++});numChecked>0?$("#wrap_noInherit").slideDown():$("#wrap_noInherit").hide()};$("#roles_editor input.editRoles").on("click",editRolesClick);$("#roles_editor input.editRoles, #roles_editor input.addRoles").on("click",editOrAddClick);editRolesClick();editOrAddClick();$("#wrap_redirectLogin input").on("click",redirectLoginClick);adjustAccessFields();redirectLoginClick()}function setupImportExport(){$("#export_data").on("click",function(){$(this).select()});$(".import_toggle input[type=radio]").on("change",function(){var $table=$(this).parents("p.import_toggle").next("table");var $fieldset=$(this).closest(".InputfieldFieldset");if($(this).is(":checked")&&$(this).val()==0){$table.hide();$fieldset.addClass("ui-priority-secondary")}else{$table.show();$fieldset.removeClass("ui-priority-secondary")}}).trigger("change");$("#import_form table td:not(:first-child)").each(function(){var html=$(this).html();var refresh=false;if(html.substring(0,1)=="{"){html="<pre>"+html+"</pre>";html=html.replace(/<br>/g,"");refresh=true}if(refresh)$(this).html(html)})}function init(){$("#wrap_filter_system input").on("click",function(){$(this).parents("form").trigger("submit")});$("#filter_field").on("change",function(){$(this).parents("form").trigger("submit")});setupAccessTab();var $templateEdit=$("#ProcessTemplateEdit");if($templateEdit.length>0){$templateEdit.find("script").remove();$templateEdit.WireTabs({items:$(".Inputfields li.WireTab"),id:"TemplateEditTabs",skipRememberTabIDs:["WireTabDelete"]})}setupImportExport();$("#fieldgroup_fields").on("change",function(){$("#_fieldgroup_fields_changed").val("changed")})}init()}function ProcessTemplateInitFields(){$("#wrap_fieldgroup_fields").trigger("asm-ready")}$(document).ready(function(){ProcessTemplate();ProcessTemplateAsmSelect()}); |