Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (() => {
- if (!!input.tableName) {
- let tableName = input.tableName;
- let fields = [];
- let cur = new SimpleTable(tableName);
- let parents = cur.getParentTables(); // имена таблиц наследуемых
- parents.forEach((element) => loopTable(element.name, fields));
- loopTable(tableName, fields);
- let names = [];
- fields.filter(value => names.push(value.name));
- data.fields = fields;
- data.names = names;
- data.choice = getChoice(tableName)
- data.mandatory = getMandatory(fields)
- data.avalible = avalible(tableName, input.formId)
- data.modalTitle = 'Overview';
- data.rejectBtnTitle = 'выход'
- data.isShow = false;
- data.isMandatory = 'printMandatory';
- data.isNotMandatory = 'printNotMandatory';
- data.isReadOnly = 'printReadOnly';
- data.isNotReadOnly = 'printNotReadOnly';
- data.All = 'printAll';
- if (input.nextState !== '') { nextState(input.nextState); ss.addInfoMessage(" = "+ input.nextState); input.nextState = '';}
- }
- })();
- function nextState(nextState) {
- let next = new SimpleRecord(input.tableName);
- next.get('sys_id', input.currentID);
- next.state = nextState;
- next.update();
- }
- function loopTable(tableName, fields) {
- let table = new SimpleRecord('sys_db_table');
- table.get('name', tableName);
- const tableID = table.sys_id;
- let record = new SimpleRecord('sys_db_column');
- record.addQuery('table_id', tableID);
- record.query();
- record.getRowCount();
- while (record.next()) {
- fields.push({
- // параметры полей
- sys_id: record.sys_id,
- tableID: tableID,
- column_type_id: record.column_type_id,
- mandatory: record.mandatory,
- name: record.column_name,
- });
- }
- }
- function Choice(choiceItem) { // возращает чеисы для одного поля
- let jsonChoice = [];
- let choice = new SimpleRecord('sys_choice');
- choice.addQuery('table_id.name', input.tableName)
- // choice.addQuery('column_name', choiceItem.sys_id)
- choice.addQuery('language', 'en')
- choice.addQuery('column_id.column_name', choiceItem.name)
- choice.query();
- while (choice.next()) {
- // jsonChoice[0] += `${choice.column_id.column_name}: '${choice.value}', // ${choice.title}\n`
- jsonChoice.push([choice.column_id.column_name+' : '+choice.value+' // '+ choice.title+ ';']);
- // ss.addInfoMessage("* "+ choice.column_id.column_name);
- }
- return jsonChoice.join('');
- }
- function getChoice(tableName) { // чейсы для всех полей
- let obj = {};
- let fields = [];
- let cur = new SimpleTable(tableName);
- let parents = cur.getParentTables(); // имена таблиц наследуемых
- parents.forEach((element) => loopTable(element.name, fields));
- loopTable(tableName, fields);
- fields = fields.filter(value => value.column_type_id == '17');
- fields.forEach( value => obj[value.name] = Choice(value) )
- return obj;
- }
- function getMandatory(fields) {
- let mandatory = [];
- fields.filter(value => value.mandatory == 1).filter(value => mandatory.push(value.name));
- return mandatory;
- }
- function avalible(tableName, formId) {
- let tableID = (new SimpleRecord('sys_db_table')).get('name', tableName).sys_id;
- let field = new SimpleRecord('sys_ui_form_element')
- field.addQuery('form_section_id.form_id.table_id', tableID)
- field.addQuery('form_section_id.form_id', formId)
- field.addQuery('column_id', 'ISNOTEMPTY')
- field.orderBy('position');
- field.query();
- let fieldLocation = {};
- let section = [];
- let fieldName = [];
- let sectionAndFieldNemes = [];
- while (field.next()) {
- if (fieldLocation[field.getDisplayValue('form_section_id')]) {
- fieldLocation[field.getDisplayValue('form_section_id')].push(field.column_id.column_name)
- } else {
- fieldLocation[field.getDisplayValue('form_section_id')] = [field.column_id.column_name];
- }
- }
- return fieldLocation;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement