artabro/wire/modules/Process/ProcessTemplate/ProcessTemplate.min.js

1 line
11 KiB
JavaScript
Raw Permalink Normal View History

2024-08-27 11:35:37 +02:00
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 $col