Savelyev_Vyacheslav

copyFieldOfJSON

Oct 17th, 2024 (edited)
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. .docFields {
  3.     display: flex !important;
  4.     flex-direction: column !important;
  5. }
  6.  
  7.       <div class="docFields">
  8.       <div class="selectedTable">
  9.       <reference
  10.           label="Имя таблицы:"
  11.           class="doc-task"
  12.           model="data.myTable"
  13.           tableName="sys_db_table"
  14.           event-change="s_widget_custom.selectedTable();"
  15.       ></reference>
  16.       </div>
  17.       <div class="selectedTask">
  18.       <reference
  19.           label="Задача:"
  20.           class="doc-task"
  21.           model="data.task"
  22.           tableName="${tableName}"
  23.           event-change="s_widget_custom.selectedTask();"
  24.       ></reference>
  25.       </div>
  26.       </div>
  27.  
  28. */
  29.  
  30.  
  31.  
  32.  
  33. async function createFlexContainer(selector) {
  34.   // Select the main item
  35.   const item = document.querySelector(selector);
  36.   if (!item) {
  37.     console.warn(`Element with selector ${selector} not found.`);
  38.     return;
  39.   }
  40.  
  41.   // Select elements to move before clearing the content
  42.   const nameWrap = item.querySelector('.src-components-dynamicForms-view-fieldWrapper-___styles-module__NameWrap___STsiA');
  43.   const inputWrap = item.querySelector('.src-components-dynamicForms-view-fieldWrapper-___styles-module__Input___bLmkj');
  44.  
  45.   // Clone necessary elements to preserve them
  46.   let nameClone = null;
  47.   let inputClone = null;
  48.  
  49.   if (nameWrap) {
  50.     const labelText = nameWrap.querySelector('.src-components-dynamicForms-view-fieldWrapper-___styles-module__Label___tjzWY');
  51.     if (labelText) {
  52.       nameClone = document.createElement('div');
  53.       nameClone.classList.add('nameContainer');
  54.       const labelTextClone = labelText.cloneNode(true); // Clone the label
  55.       labelTextClone.innerHTML += '&nbsp;'; // Add the space inside the label
  56.       nameClone.appendChild(labelTextClone); // Append to nameClone
  57.  
  58.       // Apply styles to nameContainer clone
  59.       nameClone.style.fontSize = '14px';
  60.       nameClone.style.lineHeight = '20px';
  61.       nameClone.style.fontWeight = '600';
  62.       nameClone.style.color = '#2E3238';
  63.     }
  64.   }
  65.  
  66.   if (inputWrap) {
  67.     inputClone = inputWrap.cloneNode(true); // Clone the inputWrap element
  68.   }
  69.  
  70.   // Clear existing content in the selected item
  71.   while (item.firstChild) {
  72.     item.removeChild(item.firstChild);
  73.   }
  74.  
  75.   // Create a new flex container with the 'newContainer' class
  76.   const newContainer = document.createElement('div');
  77.   newContainer.classList.add('newContainer');
  78.   newContainer.style.display = 'flex';
  79.   newContainer.style.flexDirection = 'row';
  80.   newContainer.style.alignItems = 'center';
  81.  
  82.   // Append nameClone and inputClone to the main newContainer if they exist
  83.   if (nameClone) {
  84.     newContainer.appendChild(nameClone);
  85.   }
  86.  
  87.   if (inputClone) {
  88.     const inputContainer = document.createElement('div');
  89.     inputContainer.classList.add('inputContainer');
  90.     inputContainer.appendChild(inputClone);
  91.     newContainer.appendChild(inputContainer);
  92.   }
  93.  
  94.   // Append the newContainer to the main item
  95.   await new Promise(resolve => setTimeout(resolve, 0)); // Simulate asynchronous behavior
  96.   item.appendChild(newContainer);
  97. }
  98.  
  99. // Call the function asynchronously for each selector
  100. (async () => {
  101.   await createFlexContainer('.selectedTask');
  102.   await createFlexContainer('.selectedTable');
  103. })();
  104.  
Advertisement
Add Comment
Please, Sign In to add comment