Advertisement
Savelyev_Vyacheslav

server OverviewWidget

Jun 26th, 2023
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. (() => {
  2. if (!!input.tableName) {
  3. let tableName = input.tableName;
  4. let fields = [];
  5. let cur = new SimpleTable(tableName);
  6. let parents = cur.getParentTables(); // имена таблиц наследуемых
  7. parents.forEach((element) => loopTable(element.name, fields));
  8. loopTable(tableName, fields);
  9. let names = [];
  10. fields.filter(value => names.push(value.name));
  11. data.fields = fields;
  12. data.names = names;
  13. data.choice = getChoice(tableName)
  14. data.mandatory = getMandatory(fields)
  15. data.avalible = avalible(tableName, input.formId)
  16. data.modalTitle = 'Overview';
  17. data.rejectBtnTitle = 'выход'
  18. data.isShow = false;
  19. data.isMandatory = 'printMandatory';
  20. data.isNotMandatory = 'printNotMandatory';
  21. data.isReadOnly = 'printReadOnly';
  22. data.isNotReadOnly = 'printNotReadOnly';
  23. data.All = 'printAll';
  24. if (input.nextState !== '') { nextState(input.nextState); ss.addInfoMessage(" = "+ input.nextState); input.nextState = '';}
  25. }
  26. })();
  27.  
  28. function nextState(nextState) {
  29. let next = new SimpleRecord(input.tableName);
  30. next.get('sys_id', input.currentID);
  31. next.state = nextState;
  32. next.update();
  33. }
  34.  
  35.  
  36. function loopTable(tableName, fields) {
  37. let table = new SimpleRecord('sys_db_table');
  38. table.get('name', tableName);
  39. const tableID = table.sys_id;
  40. let record = new SimpleRecord('sys_db_column');
  41. record.addQuery('table_id', tableID);
  42. record.query();
  43. record.getRowCount();
  44. while (record.next()) {
  45. fields.push({
  46. // параметры полей
  47. sys_id: record.sys_id,
  48. tableID: tableID,
  49. column_type_id: record.column_type_id,
  50. mandatory: record.mandatory,
  51. name: record.column_name,
  52. });
  53. }
  54. }
  55.  
  56. function Choice(choiceItem) { // возращает чеисы для одного поля
  57. let jsonChoice = [];
  58. let choice = new SimpleRecord('sys_choice');
  59. choice.addQuery('table_id.name', input.tableName)
  60. // choice.addQuery('column_name', choiceItem.sys_id)
  61. choice.addQuery('language', 'en')
  62. choice.addQuery('column_id.column_name', choiceItem.name)
  63. choice.query();
  64. while (choice.next()) {
  65. // jsonChoice[0] += `${choice.column_id.column_name}: '${choice.value}', // ${choice.title}\n`
  66. jsonChoice.push([choice.column_id.column_name+' : '+choice.value+' // '+ choice.title+ ';']);
  67. // ss.addInfoMessage("* "+ choice.column_id.column_name);
  68. }
  69. return jsonChoice.join('');
  70. }
  71.  
  72. function getChoice(tableName) { // чейсы для всех полей
  73. let obj = {};
  74. let fields = [];
  75. let cur = new SimpleTable(tableName);
  76. let parents = cur.getParentTables(); // имена таблиц наследуемых
  77. parents.forEach((element) => loopTable(element.name, fields));
  78. loopTable(tableName, fields);
  79. fields = fields.filter(value => value.column_type_id == '17');
  80. fields.forEach( value => obj[value.name] = Choice(value) )
  81. return obj;
  82. }
  83.  
  84. function getMandatory(fields) {
  85. let mandatory = [];
  86. fields.filter(value => value.mandatory == 1).filter(value => mandatory.push(value.name));
  87. return mandatory;
  88. }
  89.  
  90. function avalible(tableName, formId) {
  91. let tableID = (new SimpleRecord('sys_db_table')).get('name', tableName).sys_id;
  92. let field = new SimpleRecord('sys_ui_form_element')
  93. field.addQuery('form_section_id.form_id.table_id', tableID)
  94. field.addQuery('form_section_id.form_id', formId)
  95. field.addQuery('column_id', 'ISNOTEMPTY')
  96. field.orderBy('position');
  97. field.query();
  98. let fieldLocation = {};
  99. let section = [];
  100. let fieldName = [];
  101. let sectionAndFieldNemes = [];
  102. while (field.next()) {
  103. if (fieldLocation[field.getDisplayValue('form_section_id')]) {
  104. fieldLocation[field.getDisplayValue('form_section_id')].push(field.column_id.column_name)
  105. } else {
  106. fieldLocation[field.getDisplayValue('form_section_id')] = [field.column_id.column_name];
  107. }
  108. }
  109. return fieldLocation;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement