![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/tech_preview/hr/ |
Upload File : |
hr.work_flows.makeFilterConfigsList = function(host, isChangeEmployee){ return new Promise(function(resolve, reject){ if (isChangeEmployee){ var filterConfigListValueDic = {}; for (var i = 0; i < host.filterConfigList.length; i++){ if (!host.filterConfigList[i].display) continue; filterConfigListValueDic[host.filterConfigList[i].name] = host.filterConfigList[i].value; } } var filterDic = { period: true }; if (host.database.work_flow_filter_configs.items.length > 0){ filterDic = EncodingClass.string.toVariable(host.database.work_flow_filter_configs.items[0].config); } var itemsAssignto = [ {value: "all", text: LanguageModule.text("txt_all_assign_to"), isLeaf: true} ]; var itemsRelatedPerson = [ {value: "all", text: LanguageModule.text("txt_all_related_person"), isLeaf: true} ]; if (isChangeEmployee || filterDic["related_person"] || filterDic["assign_to"]){ var listOrgPriv = []; for (var i = 0; i < host.database.work_flow_members.items.length; i++){ listOrgPriv.push(host.database.work_flow_members.items[i].orgid); } for (var i = 0; i < host.database.work_flow_admin_privileges.items.length; i++){ listOrgPriv.push(-host.database.work_flow_admin_privileges.items[i].employeeid); } var data; contentModule.makeOrgEmpDicPrivilegesWorkFlow(host, listOrgPriv); var x = contentModule.getMemberOfEmployeeSelectMenu(host); x.splice(0, 1); itemsAssignto = itemsAssignto.concat(x); itemsRelatedPerson = itemsRelatedPerson.concat(x); } if (host.filterConfigList) host.filterConfigList.length = 0; else host.filterConfigList = []; host.filterConfigList.push( { name: "opening", display: true, value: 1, system: true, main: true, text: LanguageModule.text("txt_status_object"), itemsList: [ {value: "all", text: hr.isMobile? LanguageModule.text("txt_all") : LanguageModule.text("txt_all")}, {value: 1, text: LanguageModule.text("txt_using")}, {value: 0, text: LanguageModule.text("txt_archived")} ] }, { name: "assign_to", display: filterDic["assign_to"], main: true, tree_leaf: true, text: LanguageModule.text("txt_assign_to"), value: (host.employeeOfMe.length > 0)? host.employeeOfMe[0] : "all", itemsList: itemsAssignto }, { name: "related_person", display: filterDic["related_person"], main: true, tree_leaf: true, text: LanguageModule.text("txt_related_person"), value: "all", itemsList: itemsRelatedPerson } ); var columnList1 = contentModule.getColumnListFromDatatype(host, "objects", {}); if (host.dataWork_flowView.type_extra_of_object != 0){ var columnList2 = contentModule.getColumnListFromTypeid(host, host.dataWork_flowView.type_extra_of_object, {}, true); columnList2.forEach(function(item){ item.extra = true; }); columnList = columnList1.concat(columnList2); } else { columnList = columnList1; } var typeDic = contentModule.makeDictionaryIndex(host.database.typelists.items); var listPromise = []; columnList.forEach(function(item){ var tIndex = typeDic[item.type]; var type = host.database.typelists.items[tIndex].type; if (item.value == "work_flowid") return; if (item.value == "period"){ var periodsList = [{value: "all", text: LanguageModule.text("txt_all_period")}]; for (var i = 0; i < host.database.work_flow_periods.items.length; i++){ periodsList.push({ value: host.database.work_flow_periods.items[i].id, text: host.database.work_flow_periods.items[i].name }); } var x = contentModule.getObjectPeriodSystemList(); for (var i = 0; i < x.length; i++){ periodsList.push({ value: x[i].id, text: x[i].name }); } var x = { name: item.value, value: "all", display: filterDic[item.value], main: item.main, text: item.text, extra: item.extra, itemsList: periodsList }; host.filterConfigList.push(x); } else if (contentModule.listTypeSelectmenu.indexOf(type) >= 0){ var x = { name: item.value, value: "all", display: filterDic[item.value], main: item.main, text: item.text, extra: item.extra }; if (type == "member_of_employee") x.tree_leaf = true; else if (type == "member_of_department") x.tree = true; if (isChangeEmployee || filterDic[item.value]){ listPromise.push(new Promise(function(rs, rj){ contentModule.loadListPrimaryTypeEnum(type).then(function(itemsList){ if (type == "nation_city"){ itemsList.forEach(function(nItem){ nItem.items.unshift({value: 0, text: LanguageModule.text("txt_all_city")}); }); itemsList.unshift({ value: 0, text: LanguageModule.text("txt_all_nation"), items: [{value: 0, text: LanguageModule.text("txt_all_city")}] }); x.nation_city = true; x.value = [0, 0]; } else { if (itemsList.length > 0){ itemsList[0].value = "all"; itemsList[0].text = hr.isMobile? LanguageModule.text("txt_all") : LanguageModule.text("txt_all") + " - " + item.text; } } x.itemsList = itemsList; rs(); }); })); } host.filterConfigList.push(x); } else if (type == "enum" || type == "extends_enum" || host.database.typelists.items[tIndex].type2 == "enum"){ var x = { name: item.value, value: "all", display: filterDic[item.value], main: item.main, text: item.text, extra: item.extra }; if (isChangeEmployee || filterDic[item.value]){ x.itemsList = [{value: "all", text: hr.isMobile? LanguageModule.text("txt_all") : LanguageModule.text("txt_all") + " - " + item.text}]; var itemsList = []; contentModule.getDetailsExtends(host, itemsList, item.type); for (var i = 0; i < itemsList.length; i++){ x.itemsList.push({value: itemsList[i].localid, text: itemsList[i].text}); } } host.filterConfigList.push(x); } }); Promise.all(listPromise).then(function(value){ if (isChangeEmployee){ for (var i = 0; i < host.filterConfigList.length; i++){ if (filterConfigListValueDic[host.filterConfigList[i].name]) host.filterConfigList[i].value = filterConfigListValueDic[host.filterConfigList[i].name]; } } resolve(); }); }); }; hr.work_flows.loadObjectsListByIDList = function(host, objectsList){ return new Promise(function(resolve, reject){ var objectsList1 = EncodingClass.string.duplicate(objectsList); objectsList1.sort(function(a, b){ return a.id - b.id; }); FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "work_flows_load_objects_by_idlist"}, {name: "objectsList", value: EncodingClass.string.fromVariable(objectsList1)} ], func: function(success, message){ if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); var x = {database: { user_marked: host.database.user_marked }}; contentModule.makeDatabaseContent(x, st); contentModule.makeUserMarkerData(x, "objects"); var objectsDic = contentModule.makeDictionaryIndex(x.database.objects.items); var k; for (var i = 0; i < objectsList.length; i++){ k = objectsDic[objectsList[i].id]; if (k >= 0){ for (var c in x.database.objects.items[k]){ objectsList[i][c] = x.database.objects.items[k][c]; } } } x.database.objects.items = objectsList; hr.work_flows.loadExtraDataByObjectIdList(host, x).then(function(){ resolve(x.database.objects); }); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.loadAllDataOfWorkFlow = function(host, id){ return new Promise(function(resolve, reject){ FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "work_flows_load_all_data"}, {name: "id", value: id} ], func: function(success, message){ if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); var index = host.database.work_flows.getIndex(id); host.dataWork_flowView = st.data; if (index >= 0) host.dataWork_flowView.marked = host.database.work_flows.items[index].marked; delete st.data; contentModule.makeDatabaseContent(host, st); contentModule.makePrivilegeObjects(host); contentModule.makeObjectPermissionData(host); hr.work_flows.makeFilterConfigsList(host).then(function(){ var x = [], y = []; for (var i = 0; i < host.database.objects.items.length; i++){ if (!host.database.objects.items[i].privView) continue; if (host.employeeOfMe.length > 0 && (host.database.objects.items[i].assign_to == host.employeeOfMe[0] || host.database.objects.items[i].employeeRelatedDic[host.employeeOfMe[0]])){ x.push({ id: host.database.objects.items[i].id, privView: host.database.objects.items[i].privView, privEdit: host.database.objects.items[i].privEdit, assign_to: host.database.objects.items[i].assign_to, employeeRelatedDic: host.database.objects.items[i].employeeRelatedDic }) } else { y.push({ id: host.database.objects.items[i].id, privView: host.database.objects.items[i].privView, privEdit: host.database.objects.items[i].privEdit, assign_to: host.database.objects.items[i].assign_to, employeeRelatedDic: host.database.objects.items[i].employeeRelatedDic }); } } host.objectsList = x.concat(y); var isfilterAssignTo = false; for (var i = 0; i < host.filterConfigList.length; i++){ if (host.filterConfigList[i].name == "assign_to"){ if (host.filterConfigList[i].value > 0 && host.filterConfigList[i].display) isfilterAssignTo = true; break; } } host.onlyViewTable = false; if (isfilterAssignTo){ if (x.length > hr.objects_kanban_view_limit){ host.viewType = "table"; host.onlyViewTable = true; } } else { if (host.objectsList.length > hr.objects_kanban_view_limit){ host.viewType = "table"; host.onlyViewTable = true; } } var objectsList = []; objectsList.push.apply(objectsList, host.objectsList.splice(0, 500)); host.loadObjectDone = host.objectsList.length == 0; hr.work_flows.loadObjectsListByIDList(host, objectsList).then(function(objects){ host.database.objects = objects; resolve(); }); }); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.deleteWork_flow = function(host, id){ return new Promise(function(resolve,reject){ ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_delete.php", params: [{name: "id", value: id}], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var index = host.database.work_flows.getIndex(id); host.database.work_flows.items.splice(index, 1); resolve(); } else if (message == "lock_system"){ ModalElement.alert({message: LanguageModule.text("war_txt_system_lock")}); } else if (message == "failed_used"){ ModalElement.alert({ message: LanguageModule.text("war_txt_can_not_delete") }); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.deleteWork_flowConfirm = function(host, id){ return new Promise(function(resolve,reject){ var index = host.database.work_flows.getIndex(id); ModalElement.question({ title: LanguageModule.text("war_title_delete_work_flow"), message: LanguageModule.text2("war_txt_detele", [host.database.work_flows.items[index].name]), onclick: function(sel){ if (sel == 0){ hr.work_flows.deleteWork_flow(host, id).then(function(value){ resolve(value); }); } } }); }); }; hr.work_flows.addObjectsSubmit = function(host, data){ return new Promise(function(resolve, reject){ data.general_information.extrainfo = EncodingClass.string.fromVariable(data.general_information.extrainfo); data.general_information.attachments = EncodingClass.string.fromVariable(data.general_information.attachments); data.general_information.assign_to = data.employee.assign_to; var saveFunc = function(){ ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_add_object.php", params: [ {name: "data", value: EncodingClass.string.fromVariable(data)} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message. substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); fconnector.refresh("extradata_objects_links"); fconnector.refresh("extradata_objects"); st.extrainfo = EncodingClass.string.toVariable(st.extrainfo); if (data.extra_data) st.extra_data = data.extra_data; else st.extra_data = {}; st.privView = privView; st.privEdit = privEdit; st.employeeRelatedDic = {}; st.employeeRelatedDic[st.assign_to] = true; var orgsDic = contentModule.makeDictionaryIndex(host.database.orgs.items); var k; for (var i = 0; i < data.employee.priv_view.length; i++){ if (data.employee.priv_view[i] > 0){ k = orgsDic[data.employee.priv_view[i]]; if (k >= 0){ for (var x in host.database.orgs.items[k].employeeDic){ st.employeeRelatedDic[x] = host.database.orgs.items[k].employeeDic[x]; } } } else { st.employeeRelatedDic[-data.employee.priv_view[i]] = true; } } for (var i = 0; i < data.employee.priv_edit.length; i++){ if (data.employee.priv_edit[i] > 0){ k = orgsDic[data.employee.priv_edit[i]]; if (k >= 0){ for (var x in host.database.orgs.items[k].employeeDic){ st.employeeRelatedDic[x] = host.database.orgs.items[k].employeeDic[x]; } } } else { st.employeeRelatedDic[-data.employee.priv_edit[i]] = true; } } host.database.objects.items.push(st); resolve(); host.drawWorkFlowViewContentFunc(); if (privView) hr.work_flows.viewObjectsPre(host, st.id); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; var privView = false; var privEdit = false; if (systemconfig.privSystem >= 2 || data.employee.assign_to == host.employeeOfMe[0]){ privView = true; privEdit = true; } else { for (var i = 0; i < host.database.work_flow_admin_privileges.items.length; i++){ if (host.database.work_flow_admin_privileges.items[i].employeeid == host.employeeOfMe[0]){ privView = true; privEdit = true; } } if (!privView){ for (var i = 0; i < data.employee.priv_edit.length; i++){ if (host.empOrgMeDic[data.employee.priv_edit[i]]){ privView = true; privEdit = true; break; } } } if (!privView){ for (var i = 0; i < data.employee.priv_view.length; i++){ if (host.empOrgMeDic[data.employee.priv_view[i]]){ privView = true; break; } } } } if (!privView){ ModalElement.question({ title: LanguageModule.text("txt_warning"), message: LanguageModule.text("war_txt_miss_all_permission_with_object"), onclick: function(sel){ if (sel == 0){ saveFunc(); } } }); return; } if (!privEdit){ ModalElement.question({ title: LanguageModule.text("txt_warning"), message: LanguageModule.text("war_txt_miss_permission_edit_with_object"), onclick: function(sel){ if (sel == 0){ saveFunc(); } } }); return; } saveFunc(); }); }; hr.work_flows.addObjects = function(host){ ModalElement.show_loading(); hr.work_flows.objectsLoadPermissions(host, 0).then(function(employeeData){ ModalElement.close(-1); var formContainer = DOMElement.div({}); var getValueFunction; var params = { title: LanguageModule.text("txt_add_object"), formContainer: formContainer, type_extra_of_object: host.dataWork_flowView.type_extra_of_object, getValueFunction: getValueFunction, employeeData: employeeData, frameList: host.frameList, func: { save: function(data){ return hr.work_flows.addObjectsSubmit(host, data); } } }; if (host.dataWork_flowView.type_extra_of_object != 0){ params.formExtraDataContainer = DOMElement.div({}); contentModule.makeFormData({ typeid: host.dataWork_flowView.type_extra_of_object, formid: hr.isMobile? host.dataWork_flowView.mobile_input_form_extra_of_object : host.dataWork_flowView.input_form_extra_of_object, formContainer: params.formExtraDataContainer, typelists: host.database.typelists.items, variableType: "user" }).then(function(getValue){ params.getValueExtraDataFunction = getValue; }); } theme.workFlowAddObject(params); contentModule.makeFormData({ typeid: host.form_config.objects.typeid, formid: host.form_config.objects.input_form, formContainer: formContainer, typelists: host.database.typelists.items, variableType: "system" }).then(function(getValue){ formContainer.formFragment.setContext('host', host); params.getValueFunction = getValue; absol.form.traversal(formContainer.formFragment.view, function(item){ if (item.node.tag === "TextInput") { item.node.domElt.focus(); item.stop(); return; } }); formContainer.formFragment.afterEntryCompleted().then(function(){ var elt = absol.form.findComponent(formContainer.formFragment.view, { name: 'type_object_work_flowid', depth: false }); if (elt){ elt.attributes.value = host.work_flowid; elt.domElt.disabled = true; } }); }); }); }; hr.work_flows.changeObjectPeriod = function(host, id, period){ if (period == host.dataObjectEdit.period) return; ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_change_object_period.php", params: [{ name: "data", value: EncodingClass.string.fromVariable({ id: id, period: period }) }], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var oldPeriod = host.dataObjectEdit.period; host.dataObjectEdit.period = period; host.drawGeneralInforFunc(); var index = host.database.objects.getIndex(id); host.database.objects.items[index].period = period; host.drawWorkFlowViewContentFunc(); if (host.redraw_history_func){ host.redraw_history_func(); } } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; hr.work_flows.editObjectsSubmit = function(host, id, getValueFunction){ return new Promise(function(resolve, reject){ var data = getValueFunction(); if (!data) return; var ischange = contentModule.isChanged(host.dataObjectEdit, data, ["name", "period", "priority", "attachments", "description", "available", "extrainfo"]); if (!ischange){ resolve(); } data.id = host.dataObjectEdit.id; data.ver = host.dataObjectEdit.ver; data.extrainfo = EncodingClass.string.fromVariable(data.extrainfo); data.attachments = EncodingClass.string.fromVariable(data.attachments); ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_edit_object.php", params: [ {name: "data", value: EncodingClass.string.fromVariable(data)}, {name: "old_data", value: EncodingClass.string.fromVariable(host.dataObjectEdit)} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message. substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); st.extrainfo = EncodingClass.string.toVariable(st.extrainfo); st.attachments = EncodingClass.string.toVariable(st.attachments); st.privView = true; st.privEdit = true; var index = host.database.objects.getIndex(id); st.marked = host.database.objects.items[index].marked; st.extra_data = host.database.objects.items[index].extra_data; st.employeeRelatedDic = host.database.objects.items[index].employeeRelatedDic; host.database.objects.items[index] = st; host.dataObjectEdit = st; host.drawGeneralInforFunc(); host.holder.name = st.name; host.layoutViewObject.processlbar.value = st.period; host.drawWorkFlowViewContentFunc(); if (host.redraw_history_func){ host.redraw_history_func(); } resolve(); } else if (message == "edited" || message == "deleted"){ ModalElement.alert({ message: LanguageModule.text("war_txt_failed_ver_reload_data"), func: function(){ hr.work_flows.editObjectPre(host, id); } }); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.editObjectsClose = function(host, id, getValueFunction){ return new Promise(function(resolve, reject){ var data = getValueFunction("no_alert"); if (!data){ resolve(); } var ischange = contentModule.isChanged(host.dataObjectEdit, data, ["name", "period", "priority", "attachments", "description", "available", "extrainfo"]); if (!ischange){ resolve(); return; } contentModule.questionChange({ onclick: function(sel){ if (sel == 0){ resolve(hr.work_flows.editObjectsSubmit(host, id, getValueFunction)); } else if (sel == 1){ resolve(); } } }); }); }; hr.work_flows.editObject = function(host, id){ var formContainer = DOMElement.div({}); theme.workFlowEditObject({ title: LanguageModule.text("txt_general_information"), frameList: host.frameList, formContainer: formContainer, func: { save: function(){ return hr.work_flows.editObjectsSubmit(host, id, getValueFunction); }, close: function(){ return hr.work_flows.editObjectsClose(host, id, getValueFunction); } } }); var getValueFunction; contentModule.makeFormData({ typeid: host.form_config.objects.typeid, formid: host.form_config.objects.input_form, formContainer: formContainer, initialValue: host.dataObjectEdit, typelists: host.database.typelists.items, variableType: "system" }).then(function(getValue){ formContainer.formFragment.setContext('host', host); getValueFunction = getValue; absol.form.traversal(formContainer.formFragment.view, function(item){ if (item.node.tag === "TextInput") { item.node.domElt.focus(); item.stop(); return; } }); var elt = absol.form.findComponent(formContainer.formFragment.view, { name: 'type_object_work_flowid', depth: false }); if (elt){ elt.domElt.disabled = true; } }); }; hr.work_flows.editObjectPre = function(host, id){ ModalElement.show_loading(); FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "objects_load_by_id"}, {name: "id", value: id} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ host.dataObjectEdit = EncodingClass.string.toVariable(message.substr(2)); if (host.dataObjectEdit.extrainfo == "") host.dataObjectEdit.extrainfo = {}; else host.dataObjectEdit.extrainfo = EncodingClass.string.toVariable(host.dataObjectEdit.extrainfo); if (host.dataObjectEdit.attachments == "") host.dataObjectEdit.attachments = {}; else host.dataObjectEdit.attachments = EncodingClass.string.toVariable(host.dataObjectEdit.attachments); hr.work_flows.editObject(host, id); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }) }; hr.work_flows.getGeneralInformationCtn = function(host, id){ var viewGeneralInformation = DOMElement.div({}); host.drawGeneralInforFunc = function(){ contentModule.makeOutputFormData({ typeid: host.form_config.objects.typeid, formid: host.form_config.objects.output_form, initialValue: host.dataObjectEdit, formContainer: viewGeneralInformation, typelists: host.database.typelists.items, variableType: "system" }).then(function(getValue){ viewGeneralInformation.formFragment.setContext('host', host); }); }; host.drawGeneralInforFunc(); return viewGeneralInformation; }; hr.work_flows.loadExtraDataByObjectIdList = function(host, x){ return new Promise(function(resolve, reject){ if (x.database.objects.items.length == 0){ resolve(); return; } if (fconnector === undefined){ setTimeout(function(){ hr.work_flows.loadExtraDataByObjectIdList(host, x).then(function(value){ resolve(value); }) }, 50); return; } else if (fconnector === null){ resolve(); return; } var objectidDic = {}, minID, maxID; for (var i = 0; i < x.database.objects.items.length; i++){ x.database.objects.items[i].extra_data = {}; objectidDic[x.database.objects.items[i].id] = i; if (!minID){ minID = x.database.objects.items[i].id; maxID = x.database.objects.items[i].id; } else { if (minID > x.database.objects.items[i].id) minID = x.database.objects.items[i].id; if (maxID < x.database.objects.items[i].id) maxID = x.database.objects.items[i].id; } } var pattern = { type: "struct", cond: "and", children: { objectid: { type: "number", cond: "[range]", minval: minID, maxval: maxID }, extraid: { type: "number", cond: "true" } } }; fconnector.search("extradata_objects_links", pattern, function(value1) { if (value1 && value1.length > 0){ fconnector.read("extradata_objects_links", value1, function (success2, value2){ if (success2){ var extraidList = [], extraDic = {}; value2.forEach(function(linkItem){ if (objectidDic[linkItem.value.objectid] !== undefined){ extraidList.push(linkItem.value.extraid); extraDic[linkItem.value.extraid] = linkItem.value.objectid; } }); if (extraidList.length > 0){ fconnector.read("extradata_objects", extraidList, function (success3, extradata_objects){ if (success3){ var objectid, oIndex; extradata_objects.forEach(function(extraItem){ objectid = extraDic[extraItem.id]; if (objectid){ oIndex = objectidDic[objectid]; if (oIndex !== undefined){ x.database.objects.items[oIndex].extra_data = extraItem.value; } } }); resolve(); } else { resolve(); } }); } else { resolve(); } } else { resolve(); } }); } else { resolve(); } }); }); }; hr.work_flows.loadExtraDataByObjectId = function(host, objectid){ return new Promise(function(resolve, reject){ if (fconnector === undefined){ setTimeout(function(){ hr.work_flows.loadExtraDataByObjectId(host, objectid).then(function(value){ resolve(value); }) }, 50); return; } else if (fconnector === null){ ModalElement.alert({message: "Lỗi dữ liệu"}); return; } var pattern = { type: "struct", cond: "and", children: { objectid: { type: "number", cond: "eq", value: objectid }, extraid: { type: "number", cond: "true" } } }; fconnector.search("extradata_objects_links", pattern, function(value1) { if (value1 && value1.length > 0){ fconnector.read("extradata_objects_links", value1[value1.length - 1], function (success2, value2){ console.log(value2); if (success2){ fconnector.read("extradata_objects", value2.extraid, function (success3, value3){ if (success3){ resolve({ id: value2.extraid, data: value3 }); } else { resolve({id: 0}); } }); } else { resolve({id: 0}); } }); } else { resolve({id: 0}); } }); }); }; hr.work_flows.getExtraDataCtn = function(host, id){ var viewExtraData = DOMElement.div({}); host.drawExtraDataFunc = function(){ hr.work_flows.loadExtraDataByObjectId(host, id).then(function(value){ console.log(value); contentModule.makeOutputFormData({ typeid: host.dataWork_flowView.type_extra_of_object, formid: hr.isMobile? host.dataWork_flowView.mobile_output_form_extra_of_object : host.dataWork_flowView.output_form_extra_of_object, formContainer: viewExtraData, initialValue: value.data, typelists: host.database.typelists.items, variableType: "user" }).then(function(getValue){}); }); }; host.drawExtraDataFunc(); return viewExtraData; }; hr.work_flows.objectsLoadPermissions = function(host, id){ return new Promise(function(resolve, reject){ FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "objects_load_permissons"}, {name: "id", value: id}, {name: "work_flowid", value: host.work_flowid} ], func: function(success, message){ if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); var data = st.data; delete st.data; if (id == 0) data.assign_to = host.employeeOfMe[0]; contentModule.makeDatabaseContent(host, st); var listOrgPriv = []; for (var i = 0; i < host.database.work_flow_members.items.length; i++){ listOrgPriv.push(host.database.work_flow_members.items[i].orgid); } for (var i = 0; i < host.database.work_flow_admin_privileges.items.length; i++){ listOrgPriv.push(-host.database.work_flow_admin_privileges.items[i].employeeid); } var employeeDic = {}; for (var i = 0; i < host.database.employees.items.length; i++){ employeeDic[host.database.employees.items[i].userid] = host.database.employees.items[i].id; } var k ; for (var i = 0; i < host.database.users.items.length; i++){ if (host.database.users.items[i].privilege >= 2){ k = employeeDic[host.database.users.items[i].homeid]; if (k >= 0){ listOrgPriv.push(-k); } } } contentModule.makeOrgEmpDicPrivilegesWorkFlow(host, listOrgPriv); data.itemsList = contentModule.getOrgsAndEmployeesListSelectTreeMenu(host); data.itemsList.shift(0, 1); data.items_assign_to_List = contentModule.getMemberOfEmployeeSelectMenu(host); data.items_assign_to_List.shift(0, 1); data.privViewValues = []; data.privEditValues = []; if (!host.userSendNotiList) host.userSendNotiList = []; host.userSendNotiList.length = 0; var eIndex = host.database.employees.getIndex(data.assign_to); if (eIndex >= 0){ host.userSendNotiList.push(host.database.employees.items[eIndex].userid); } var orgsDic = contentModule.makeDictionaryIndex(host.database.orgs.items); var f1 = function(oIndex){ var ni; for (var i = 0; i < host.database.orgs.items[oIndex].employeeIndexList.length; i++){ ni = host.database.orgs.items[oIndex].employeeIndexList[i]; if (host.userSendNotiList.indexOf(host.database.employees.items[ni].userid) < 0){ host.userSendNotiList.push(host.database.employees.items[ni].userid); } } for (var i = 0; i < host.database.orgs.items[oIndex].childIndexList.length; i++){ f1(host.database.orgs.items[oIndex].childIndexList[i]); } }; for (var i = 0; i < host.database.object_permissions.items.length; i++){ if (host.database.object_permissions.items[i].priv == "view"){ data.privViewValues.push(host.database.object_permissions.items[i].orgid); } else { data.privEditValues.push(host.database.object_permissions.items[i].orgid); } if (host.database.object_permissions.items[i].orgid > 0){ var k = orgsDic[host.database.object_permissions.items[i].orgid]; if (k >= 0){ f1(k); } } else { var eIndex = host.database.employees.getIndex(-host.database.object_permissions.items[i].orgid); if (eIndex >= 0){ host.userSendNotiList.push(host.database.employees.items[eIndex].userid); } } } resolve(data); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.getEmployeeElt = function(host, data, type){ return theme.formWork_flowEmployeeObject({ data: data, type: type }); }; hr.work_flows.editObjectEmployeeSubmit = function(host, id, value){ return new Promise(function(resolve, reject){ var saveFunc = function(){ ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_edit_object_employee.php", params: [ {name: "objectid", value: id}, {name: "data", value: EncodingClass.string.fromVariable(value)} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ resolve(); if (!privView){ var index = host.database.objects.getIndex(id); if (index >= 0) host.database.objects.items[index].privView = false; host.frameList.removeLast(); host.drawWorkFlowViewContentFunc(true); } else { host.drawEmployeeFunc(); if (!privEdit){ host.layoutViewObject.removePrivEdit(); contentModule.activitiesInformation({ workSelected: "both", tableName: "objects", instanceid: id, addActivitiesSelected: "none", frameList: host.frameList }).then(function(result){ var chart = result.getChartContent(); DOMElement.removeAllChildren(host.layoutViewObject.chartCtn); host.layoutViewObject.chartCtn.appendChild(chart); var activities = result.getActivitiesContent(); DOMElement.removeAllChildren(host.layoutViewObject.activitiesCtn); host.layoutViewObject.activitiesCtn.appendChild(activities); }); } if (host.generalEmpForOrg){ var index = host.database.objects.getIndex(id); if (index >= 0){ host.database.objects.items[index].employeeRelatedDic = {}; host.database.objects.items[index].employeeRelatedDic[value.assign_to] = true; var orgsDic = contentModule.makeDictionaryIndex(host.database.orgs.items); var k; for (var i = 0; i < value.priv_view.length; i++){ if (value.priv_view[i] > 0){ k = orgsDic[value.priv_view[i]]; if (k >= 0){ for (var x in host.database.orgs.items[k].employeeDic){ host.database.objects.items[index].employeeRelatedDic[x] = host.database.orgs.items[k].employeeDic[x]; } } } else { host.database.objects.items[index].employeeRelatedDic[-value.priv_view[i]] = true; } } for (var i = 0; i < value.priv_edit.length; i++){ if (value.priv_edit[i] > 0){ k = orgsDic[value.priv_edit[i]]; if (k >= 0){ for (var x in host.database.orgs.items[k].employeeDic){ host.database.objects.items[index].employeeRelatedDic[x] = host.database.orgs.items[k].employeeDic[x]; } } } else { host.database.objects.items[index].employeeRelatedDic[-value.priv_edit[i]] = true; } } } } if (host.redraw_history_func){ host.redraw_history_func(); } } } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; value.priv_edit = absol.array.arrayUnique(value.priv_edit); value.priv_view = absol.array.arrayUnique(value.priv_view); var privView = false; var privEdit = false; if (systemconfig.privSystem >= 2 || value.assign_to == host.employeeOfMe[0]){ privView = true; privEdit = true; } else { for (var i = 0; i < host.database.work_flow_admin_privileges.items.length; i++){ if (host.database.work_flow_admin_privileges.items[i].employeeid == host.employeeOfMe[0]){ privView = true; privEdit = true; } } if (!privView){ for (var i = 0; i < value.priv_edit.length; i++){ if (host.empOrgMeDic[value.priv_edit[i]]){ privView = true; privEdit = true; break; } } } if (!privView){ for (var i = 0; i < value.priv_view.length; i++){ if (host.empOrgMeDic[value.priv_view[i]]){ privView = true; break; } } } } if (!privView){ ModalElement.question({ title: LanguageModule.text("txt_warning"), message: LanguageModule.text("war_txt_miss_all_permission_with_object"), onclick: function(sel){ if (sel == 0){ saveFunc(); } } }); return; } if (!privEdit){ ModalElement.question({ title: LanguageModule.text("txt_warning"), message: LanguageModule.text("war_txt_miss_permission_edit_with_object"), onclick: function(sel){ if (sel == 0){ saveFunc(); } } }); return; } saveFunc(); }); }; hr.work_flows.editObjectEmployee = function(host, id){ ModalElement.show_loading(); hr.work_flows.objectsLoadPermissions(host, id).then(function(data){ ModalElement.close(-1); var data_ctn = hr.work_flows.getEmployeeElt(host, data, "edit"); theme.workFlowEditObjectEmployeeForm({ title: LanguageModule.text("txt_employee"), frameList: host.frameList, data_ctn: data_ctn, func: { save: function(){ var value = data_ctn.getValue(); if (!value) return; return hr.work_flows.editObjectEmployeeSubmit(host, id, value); } } }); }); }; hr.work_flows.getEmployeeCtn = function(host, id){ var viewEmployee = DOMElement.div({}); host.drawEmployeeFunc = function(){ hr.work_flows.objectsLoadPermissions(host, id).then(function(data){ DOMElement.removeAllChildren(viewEmployee); viewEmployee.appendChild(hr.work_flows.getEmployeeElt(host, data, "view")); }); }; host.drawEmployeeFunc(); return viewEmployee; }; hr.work_flows.addPartnerSubmit = function(host, id, list){ return new Promise(function(resolve, reject){ ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_object_add_partner.php", params: [ {name: "objectid", value: id}, {name: "list", value: EncodingClass.string.fromVariable(list)} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); host.database.object_partner.items = st; host.drawPartnerFunc(); resolve(); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.loadLazyPartnerData = function(host){ if (!host.addPartnerPage.insertData) { setTimeout(function (host) { return function () { hr.work_flows.loadLazyPartnerData(host); } } (host), 50); return; } var xhost = { host: host, lastindex: 0, first_content: 1 } if (data_module.partnerLoading == false) { data_module.partnerLoading = true; data_module.partnerReady = false; } xhost.ffunc = function (host) { return function (content) { if (data_module.partner_class === undefined) { setTimeout(function (host, content) { return function () { host.ffunc(content); } } (host, content), 10); return; } data_module.partnerReady = true; data_module.makeDatabaseCommon({ partner: host.host.database.partner.items, partner_class_links: host.host.database.partner_class_links.items }); var partnerDic = contentModule.makeDictionaryIndex(data_module.partner.items); for (var i = 0; i < data_module.partner.items.length; i++) { data_module.partner.items[i].class = []; } var k; for (var i = 0; i < data_module.partner_class_links.items.length; i++){ k = partnerDic[data_module.partner_class_links.items[i].partnerid]; if (k >= 0) { data_module.partner.items[k].class.push(data_module.partner_class_links.items[i].classid); } } var classDic = contentModule.makeDictionaryIndex(data_module.partner_class.items); var ni, cIndex; for (var i = 0; i < data_module.partner.items.length; i++){ data_module.partner.items[i].className = ""; for (var j = 0; j < data_module.partner.items[i].class.length; j++){ ni = data_module.partner.items[i].class[j]; cIndex = classDic[ni]; if (cIndex >= 0) { data_module.partner.items[i].className += ", " + data_module.partner_class.items[cIndex].name; } } if (data_module.partner.items[i].class.length > 0){ data_module.partner.items[i].className = data_module.partner.items[i].className.substr(2); } } } } (xhost); data_module.loadPartnerFunc({ finalize: function (host) { return function (content) { host.ffunc(content); host.host.load_partner_done = 1; } } (xhost), process: function (host) { return function (content) { var st; var i, n; console.log(content.finished); host.host.load_partner_done = (content.finished) ? 1 : 0; st = { partner: content.partner, partner_class_links: content.partner_class_links, user_marked: host.host.database.user_marked.items } var x = { database: {} }; contentModule.makeDatabaseContent(x, st); contentModule.makePartnerData(x); contentModule.makePartnerClassLinksData(x); contentModule.makeUserMarkerData(host.host, "partner"); host.host.addPartnerPage.insertData(x.database.partner.items); host.host.database.partner.items = host.host.database.partner.items.concat(x.database.partner.items); host.host.database.partner_class_links.items = host.host.database.partner.items.concat(x.database.partner_class_links.items); if (host.first_content == 1) { host.first_content = 0; ModalElement.close(-1); } } } (xhost), sort: true }) // FormClass.api_call({ // url: "database_load.php", // params: [ // {name: "task", value: hr.isMobile? "partner_load_lazy_mobile" : "partner_load_lazy"}, // {name: "startIndex", value: host.database.partner.items.length}, // {name: "partnerCondition", value: host.partnerCondition} // ], // func: function(success, message){ // if (success){ // if (message.substr(0, 2) == "ok"){ // var st = EncodingClass.string.toVariable(message.substr(2)); // host.load_partner_done = st.done; // var x = { // database: {} // }; // contentModule.makeDatabaseContent(x, st); // contentModule.makePartnerData(x); // contentModule.makePartnerClassLinksData(x); // host.addPartnerPage.insertData(x.database.partner.items); // host.database.partner.items = host.database.partner.items.concat(x.database.partner.items); // host.database.partner_class_links.items = host.database.partner.items.concat(x.database.partner_class_links.items); // hr.work_flows.loadLazyPartnerData(host); // } // else { // ModalElement.alert({message: message}); // } // } // else { // ModalElement.alert({message: message}); // } // } // }); }; hr.work_flows.addPartner = function(host, id){ var addNewPartnerSubmit = function(getValueFunction){ return new Promise(function(rs, rj){ hr.partner.addPartnerSubmitFunc(host, 0, getValueFunction).then(function(st){ rs(st); }); }); }; host.addPartnerPage = theme.workFlowAddPartnerForm({ database: host.database, user_column_configsDic: host.user_column_configsDic, form_config: host.form_config, frameList: host.frameList, func: { add_new_save: function(getValueFunction){ return addNewPartnerSubmit(getValueFunction); }, ok: function(list){ return hr.work_flows.addPartnerSubmit(host, id, list); } } }); }; hr.work_flows.addPartnerPre = function(host, id){ host.load_partner_done = 0; var loadPartner = ((!data_module.partnerReady) || (data_module.partner === undefined) || (data_module.partner_class_links === undefined) || (data_module.partner_class === undefined)); ModalElement.show_loading(); FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "work_flows_load_all_partner"} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var content = EncodingClass.string.toVariable(message.substr(2)); host.load_partner_done = content.done; delete content.done; contentModule.makeDatabaseContent(host, content); if (!loadPartner){ contentModule.makeDatabaseContent(host, { partner: EncodingClass.string.duplicate(data_module.partner.items), partner_class_links: EncodingClass.string.duplicate(data_module.partner_class_links.items), partner_class: EncodingClass.string.duplicate(data_module.partner_class.items) }); } contentModule.makeCitiesIndex(host); contentModule.makePartnerData(host); contentModule.makePartnerClassLinksData(host); if (EncodingClass.type.isFunction(host.database["partner"].items.map)) contentModule.makeUserMarkerData(host, "partner"); if (!loadPartner) { host.database.partner.items.sort(function(a, b){ if (b.marked > a.marked) return 1; if (b.marked < a.marked) return -1; return a.name - b.name; }); } hr.work_flows.addPartner(host, id); if (loadPartner) hr.work_flows.loadLazyPartnerData(host); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; hr.work_flows.deletePartner = function(host, objectid, partnerid){ return new Promise(function(resolve, reject){ ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_object_delete_partner.php", params: [ {name: "objectid", value: objectid}, {name: "partnerid", value: partnerid} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ for (var i = 0; i < host.database.object_partner.items.length; i++){ if (host.database.object_partner.items[i].partnerid == partnerid){ host.database.object_partner.items.splice(i, 1); break; } } resolve(); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }) }); }; hr.work_flows.deletePartnerConfirm = function(host, objectid, partnerid){ return new Promise(function(resolve, reject){ var index = host.database.partner.getIndex(partnerid); ModalElement.question({ title: LanguageModule.text("war_title_delete_partner"), message: LanguageModule.text2("war_txt_detele", [host.database.partner.items[index].name]), onclick: function(sel){ if (sel == 0){ hr.work_flows.deletePartner(host, objectid, partnerid).then(function(value){ resolve(value); }); } } }); }); }; hr.work_flows.getPartnerCtn = function(host, id){ var viewPartner = DOMElement.div({}); host.drawPartnerFunc = function(){ var idDic = {}; for (var i = 0; i < host.database.object_partner.items.length; i++){ idDic[host.database.object_partner.items[i].partnerid] = true; } var getCellPartner = function(item){ var func = { view: function(){ hr.menu.openPartnerByID(item.id); } }; func.delete = function(){ return new Promise(function(resolve, reject){ hr.work_flows.deletePartnerConfirm(host, id, item.id).then(function(value){ resolve(value); }); }); }; if (!idDic[item.id]) return null; var res = item; res.func = func; return res; }; theme.formPartnerContentData({ database: host.database, ctn: viewPartner, form_config: host.form_config, user_column_configsDic: host.user_column_configsDic, getCellPartner: function(item){ return getCellPartner(item); } }); }; FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "work_flows_load_object_partner"}, {name: "objectid", value: id} ], func: function(success, message){ if (success){ if (message.substr(0, 2) == "ok"){ var content = EncodingClass.string.toVariable(message.substr(2)); contentModule.makeDatabaseContent(host, content); contentModule.makePartnerData(host); contentModule.makePartnerClassLinksData(host); host.drawPartnerFunc(); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); return viewPartner; }; hr.work_flows.addContactSubmit = function(host, id, list){ return new Promise(function(resolve, reject){ ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_object_add_contact.php", params: [ {name: "objectid", value: id}, {name: "list", value: EncodingClass.string.fromVariable(list)} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); host.database.object_contact.items = st; host.drawContactFunc(); resolve(); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.loadLazyContactData = function(host){ if (host.load_contact_done) return; if (!host.addContactPage.insertData){ setTimeout(function(){ hr.work_flows.loadLazyContactData(host); }, 50); return; } FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: hr.isMobile? "contact_load_lazy_mobile" : "contact_load_lazy"}, {name: "startIndex", value: host.database.contact.items.length}, {name: "conditionContact", value: host.conditionContact} ], func: function(success, message){ if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); host.load_contact_done = st.done; var x = { database: {} }; contentModule.makeDatabaseContent(x, st); host.addContactPage.insertData(x.database.contact.items); host.database.contact.items = host.database.contact.items.concat(x.database.contact.items); hr.work_flows.loadLazyContactData(host); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }) }; hr.work_flows.addContact = function(host, id){ var addNewContactSubmit = function(getValueFunction){ return new Promise(function(rs, rj){ hr.contact.addContactSubmitFunc(host, 0, getValueFunction).then(function(st){ rs(st); }); }); }; host.addContactPage = theme.workFlowAddContactForm({ employeeOfMe: host.employeeOfMe, employeeEditContactDic: host.employeeEditContactDic, database: host.database, user_column_configsDic: host.user_column_configsDic, form_config: host.form_config, frameList: host.frameList, func: { add_new_save: function(getValueFunction){ return addNewContactSubmit(getValueFunction); }, ok: function(list){ return hr.work_flows.addContactSubmit(host, id, list); } } }); hr.work_flows.loadLazyContactData(host); }; hr.work_flows.addContactPre = function(host, id){ host.load_contact_done = 0; ModalElement.show_loading(); var loadData = function(){ return new Promise(function(rs, rj){ var loadContact = true; if (data_module.contactReady){ loadContact = false; } FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: loadContact? "work_flows_load_all_contact" : "work_flows_load_all_contact_no_contact"} ], func: function(success, message){ if (success){ if (message.substr(0, 2) == "ok"){ var content = EncodingClass.string.toVariable(message.substr(2)); host.load_contact_done = content.done; delete content.done; contentModule.makeDatabaseContent(host, content); if (!loadContact){ contentModule.makeDatabaseContent(host, { contact: EncodingClass.string.duplicate(data_module.contact.items) }); } else { host.conditionContact = ""; if (host.database.user_marked.items.length > 0){ for (var i = 0; i < host.database.user_marked.items.length; i++){ if (i > 0) host.conditionContact += " AND "; host.conditionContact += "(id <> " + host.database.user_marked.items[i].taskid + ")"; } } } contentModule.makeUserMarkerData(host, "contact"); if (!loadContact){ host.database.contact.items.sort(function(a, b){ if (b.marked > a.marked) return 1; if (b.marked < a.marked) return -1; return a.name - b.name; }); } rs(); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); } Promise.all([loadData(), data_module.loadPartnerList()]).then(function(values){ ModalElement.close(-1); contentModule.makeDatabaseContent(host, {partner: values[1]}); hr.work_flows.addContact(host, id); }); }; hr.work_flows.deleteContact = function(host, objectid, contactid){ return new Promise(function(resolve, reject){ ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_object_delete_contact.php", params: [ {name: "objectid", value: objectid}, {name: "contactid", value: contactid} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ for (var i = 0; i < host.database.object_contact.items.length; i++){ if (host.database.object_contact.items[i].contactid == contactid){ host.database.object_contact.items.splice(i, 1); break; } } resolve(); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }) }); }; hr.work_flows.deleteContactConfirm = function(host, objectid, contactid){ return new Promise(function(resolve, reject){ var index = host.database.contact.getIndex(contactid); ModalElement.question({ title: LanguageModule.text("war_title_delete_contact"), message: LanguageModule.text2("war_txt_detele", [host.database.contact.items[index].name]), onclick: function(sel){ if (sel == 0){ hr.work_flows.deleteContact(host, objectid, contactid).then(function(value){ resolve(value); }); } } }); }); }; hr.work_flows.getContactCtn = function(host, id){ var viewContact = DOMElement.div({}); host.drawContactFunc = function(){ var idDic = {}; for (var i = 0; i < host.database.object_contact.items.length; i++){ idDic[host.database.object_contact.items[i].contactid] = true; } var getCellContact = function(item){ var func = { view: function(){ hr.menu.openContactByID(item.id, host.employeeEditContactDic); } }; func.delete = function(){ return new Promise(function(resolve, reject){ hr.work_flows.deleteContactConfirm(host, id, item.id).then(function(value){ resolve(value); }); }); } if (!idDic[item.id]) return null; if (systemconfig.privSystem < 2 && !host.employeeEditContactDic[item.owner]) return null; var res = item; res.func = func; return res; }; theme.formContactContentData({ database: host.database, ctn: viewContact, form_config: host.form_config, user_column_configsDic: host.user_column_configsDic, getCellContact: function(item){ return getCellContact(item); } }); }; var loadData = function(){ FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "work_flows_load_object_contact"}, {name: "objectid", value: id} ], func: function(success, message){ if (success){ if (message.substr(0, 2) == "ok"){ var content = EncodingClass.string.toVariable(message.substr(2)); contentModule.makeDatabaseContent(host, content); host.drawContactFunc(); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; if (host.loadPrivilegesContacts){ loadData(); } else { ModalElement.show_loading(); FormClass.api_call({ url: "database_load.php", params: [{name: "task", value: "load_data_orgs_emps_and_privileges"}], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); contentModule.makeDatabaseContent(host, st); contentModule.makeOrgsIndex(host); contentModule.makeEmployeeData(host); contentModule.makeEmployeesIndex(host); contentModule.makeEmployeeGroupMemberIndex(host); contentModule.makePrivilegesContactConfigs(host); host.loadPrivilegesContacts = true; loadData(); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); } return viewContact; }; hr.work_flows.closeObject = function(host, id){ return new Promise(function(resolve, reject){ var closeFunc = function(ps){ ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_close_object.php", params: [ {name: "data", value: EncodingClass.string.fromVariable(ps)} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var index = host.database.objects.getIndex(id); host.database.objects.items[index].privEdit = false; host.database.objects.items[index].closed = 1; host.database.objects.items[index].opening = 0; if (ps.data.period !== undefined) host.database.objects.items[index].period = ps.data.period; resolve(); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }) }; ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_close_object_pre.php", params: [ {name: "id", value: id} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ ModalElement.question({ title: LanguageModule.text("txt_archive_object"), message: LanguageModule.text("war_txt_close_object"), onclick: function(sel){ if (sel == 0){ var data = { id: id, closed: 1 }; closeFunc({data: data}); } } }); } else if (message.substr(0, 6) == "failed"){ var st = EncodingClass.string.toVariable(message.substr(6)); theme.formWork_flowsCloseObjectConfirm({ id: id, st: st, func: { save: function(data){ closeFunc({ data: data, meeting: st.meeting, task: st.task }); } } }); } else if (message == "deleted"){ reject("deleted"); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.editExtraDataSubmit = function(host, id, oldvalue, getValueFunction){ return new Promise(function(resolve, reject){ var data = getValueFunction(); if (!data) return; if (oldvalue.id > 0){ var ischange = EncodingClass.string.compare(oldvalue.data, data); if (!ischange){ resolve(); return; } } var old_data; if (!oldvalue.data){ var typeDict = {}; host.database.typelists.items.forEach(function(elt){ typeDict[elt.id] = elt; }); old_data = contentModule.makeDefaultData(host, host.dataWork_flowView.type_extra_of_object, typeDict[host.dataWork_flowView.type_extra_of_object], typeDict); } else { old_data = oldvalue.data; } ModalElement.show_loading(); FormClass.api_call({ url: "objects_save_extradata.php", params: [ {name: "id", value: oldvalue.id}, {name: "objectid", value: id}, {name: "data", value: EncodingClass.string.fromVariable(data)}, {name: "old_data", value: EncodingClass.string.fromVariable(old_data)} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var index = host.database.objects.getIndex(id); if (index >= 0) host.database.objects.items[index].extra_data = data; host.drawWorkFlowViewContentFunc(); fconnector.refresh("extradata_objects_links"); fconnector.refresh("extradata_objects"); host.drawExtraDataFunc(); if (host.redraw_history_func){ host.redraw_history_func(); } resolve(); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.editExtraDataClose = function(host, id, oldvalue, getValueFunction){ return new Promise(function(resolve, reject){ var data = getValueFunction("no_alert"); if (!data){ resolve(); return; } if (oldvalue.id > 0){ var ischange = EncodingClass.string.compare(oldvalue.data, data); } else { var ischange = false; } if (!ischange){ resolve(); return; } contentModule.questionChange({ onclick: function(sel){ if (sel == 0){ hr.work_flows.editExtraDataSubmit(host, id, oldvalue, getValueFunction).then(function(){ resolve(); }); } else if (sel == 1){ resolve(); } } }); }); }; hr.work_flows.editExtraData = function(host, id){ ModalElement.show_loading(); hr.work_flows.loadExtraDataByObjectId(host, id).then(function(value){ ModalElement.close(-1); var formContainer = DOMElement.div({}); theme.fromObjectEditExtraData({ title: LanguageModule.text("txt_data_extra"), formContainer: formContainer, frameList: host.frameList, func: { save: function(){ return hr.work_flows.editExtraDataSubmit(host, id, value, getValueFunction); }, cancel: function(){ return hr.work_flows.editExtraDataClose(host, id, value, getValueFunction); } } }); var getValueFunction; contentModule.makeFormData({ typeid: host.dataWork_flowView.type_extra_of_object, formid: hr.isMobile? host.dataWork_flowView.mobile_input_form_extra_of_object : host.dataWork_flowView.input_form_extra_of_object, initialValue: value.data, formContainer: formContainer, typelists: host.database.typelists.items, variableType: "user" }).then(function(getValue){ getValueFunction = getValue; }); }); }; hr.work_flows.addFromEmployeeTemplate = function(host, id){ var x = { database: { orgs: host.database.orgs, employees: host.database.employees } }; var itemsList = contentModule.getOrgsAndEmployeesListSelectTreeMenu(x); itemsList.splice(0, 1); theme.formAddFromEmployeeTemplate({ title: LanguageModule.text("txt_add_from_employee_template"), frameList: host.frameList, database: host.database, itemsList: itemsList, func: { save: function(templateid){ var saveFunc = function(){ ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_add_employee_from_template.php", params: [{name: "data", value: EncodingClass.string.fromVariable({ id: id, view: view, edit: edit })}], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ if (!privView){ var index = host.database.objects.getIndex(id); if (index >= 0) host.database.objects.items[index].privView = false; host.frameList.removeLast(); host.drawWorkFlowViewContentFunc(true); } else { host.drawEmployeeFunc(); if (!privEdit){ host.layoutViewObject.removePrivEdit(); contentModule.activitiesInformation({ workSelected: "both", tableName: "objects", instanceid: id, addActivitiesSelected: "none", frameList: host.frameList }).then(function(result){ var chart = result.getChartContent(); DOMElement.removeAllChildren(host.layoutViewObject.chartCtn); host.layoutViewObject.chartCtn.appendChild(chart); var activities = result.getActivitiesContent(); DOMElement.removeAllChildren(host.layoutViewObject.activitiesCtn); host.layoutViewObject.activitiesCtn.appendChild(activities); }); } if (host.redraw_history_func){ host.redraw_history_func(); } } if ( EncodingClass.string.compare(view, host.database.employee_templates.items[tIndex].view) || EncodingClass.string.compare(edit, host.database.employee_templates.items[tIndex].edit) ){ ModalElement.alert({message: LanguageModule.text("war_txt_add_add_from_template_invalid")}); } } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; var tIndex = host.database.employee_templates.getIndex(templateid); var view = absol.$.rootTreeValues2CheckedValues(itemsList, host.database.employee_templates.items[tIndex].view); var edit = absol.$.rootTreeValues2CheckedValues(itemsList, host.database.employee_templates.items[tIndex].edit); var viewData = []; for (var i = 0; i < view.length; i++){ if (view[i] > 0){ if (host.orgEditDic[view[i]]) viewData.push(view[i]); } else { if (host.employeeEditDic[-view[i]]) viewData.push(view[i]); } } var editData = []; for (var i = 0; i < edit.length; i++){ if (edit[i] > 0){ if (host.orgEditDic[edit[i]]) editData.push(edit[i]); } else { if (host.employeeEditDic[-edit[i]]) editData.push(edit[i]); } } view = absol.$.checkedValues2RootTreeValues(itemsList, viewData); edit = absol.$.checkedValues2RootTreeValues(itemsList, editData); var privView = false; var privEdit = false; if (systemconfig.privSystem >= 2 || host.dataObjectEdit.assign_to == host.employeeOfMe[0]){ privView = true; privEdit = true; } else { for (var i = 0; i < host.database.work_flow_admin_privileges.items.length; i++){ if (host.database.work_flow_admin_privileges.items[i].employeeid == host.employeeOfMe[0]){ privView = true; privEdit = true; } } if (!privView){ for (var i = 0; i < edit.length; i++){ if (host.empOrgMeDic[edit[i]]){ privView = true; privEdit = true; break; } } } if (!privView){ for (var i = 0; i < view.length; i++){ if (host.empOrgMeDic[view[i]]){ privView = true; break; } } } } if (!privView){ ModalElement.question({ title: LanguageModule.text("txt_warning"), message: LanguageModule.text("war_txt_miss_all_permission_with_object"), onclick: function(sel){ if (sel == 0){ saveFunc(); } } }); return; } if (!privEdit){ ModalElement.question({ title: LanguageModule.text("txt_warning"), message: LanguageModule.text("war_txt_miss_permission_edit_with_object"), onclick: function(sel){ if (sel == 0){ saveFunc(); } } }); return; } saveFunc(); } } }); }; hr.work_flows.addFromEmployeeTemplatePre = function(host, id){ ModalElement.show_loading(); FormClass.api_call({ url: "database_load.php", params: [{name: "task", value: "work_flows_load_employee_templales"}], func: function(success, message){ ModalElement.close(-1); if (success){ if(message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); contentModule.makeDatabaseContent(host, st); host.database.employee_templates.items.forEach(function(item){ item.view = []; item.edit = []; }); var templatesDic = contentModule.makeDictionaryIndex(host.database.employee_templates.items); var k; for (var i = 0; i < host.database.employee_template_details.items.length; i++){ k = templatesDic[host.database.employee_template_details.items[i].templateid]; if (host.database.employee_template_details.items[i].priv == "edit"){ host.database.employee_templates.items[k].edit.push(host.database.employee_template_details.items[i].orgid); } else { host.database.employee_templates.items[k].view.push(host.database.employee_template_details.items[i].orgid); } } hr.work_flows.addFromEmployeeTemplate(host, id); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; hr.work_flows.createEmployeeTemplateSubmit = function(host, id, data){ return new Promise(function(resolve, reject){ data.id = 0; ModalElement.show_loading(); FormClass.api_call({ url: "employee_templates_save.php", params: [{name: "data", value: EncodingClass.string.fromVariable(data)}], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); resolve(); } else if (message == "name_exist"){ ModalElement.alert({message: LanguageModule.text("war_txt_name_is_exist")}); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.createEmployeeTemplate = function(host, id){ ModalElement.show_loading(); FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "work_flows_load_create_employee_template"}, {name: "objectid", value: id} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); var view = [], edit = []; for (var i = 0; i < st.length; i++){ if (st[i].priv == "view"){ view.push(st[i].orgid); } else { edit.push(st[i].orgid); } } var itemsList = contentModule.getOrgsAndEmployeesListSelectTreeMenu({ database: host.database, employeeOfMe: host.employeeOfMe }); itemsList.splice(0, 1); theme.formEmployee_templateEdit({ title: LanguageModule.text("txt_create_employee_templale"), data: { name: "", view: view, edit: edit }, itemsList: itemsList, frameList: host.frameList, func: { save: function(data){ return hr.work_flows.createEmployeeTemplateSubmit(host, id, data); } } }); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; hr.work_flows.viewObjects = function(host, id, param2){ var wIndex = host.database.work_flows.getIndex(host.dataObjectEdit.work_flowid); host.dataObjectEdit.work_flowName = host.database.work_flows.items[wIndex].name; var cmdbutton = {}; var func = {}; func.markedFunc = function(marked){ return new Promise(function(rs, rj){ contentModule.markedFunc(host, { id: id, marked: marked, task: "objects", tablename: "objects" }).then(function(v){ rs(v); host.drawWorkFlowViewContentFunc(); }); }); }; if (host.dataObjectEdit.privEdit){ cmdbutton.close_object = function(){ hr.work_flows.closeObject(host, id).then(function rs(){ host.layoutViewObject.removePrivEdit(); host.layoutViewObject.drawInitInfor(true); host.drawWorkFlowViewContentFunc(); var index = host.database.objects.getIndex(id); host.layoutViewObject.processlbar.value = host.database.objects.items[index].period; host.objectCommentCtn.setDisabled(true); contentModule.activitiesInformation({ workSelected: "both", tableName: "objects", instanceid: id, addActivitiesSelected: "none", frameList: host.frameList }).then(function(result){ var chart = result.getChartContent(); DOMElement.removeAllChildren(host.layoutViewObject.chartCtn); host.layoutViewObject.chartCtn.appendChild(chart); var activities = result.getActivitiesContent(); DOMElement.removeAllChildren(host.layoutViewObject.activitiesCtn); host.layoutViewObject.activitiesCtn.appendChild(activities); }); }, function rj(){ var index = host.database.objects.getIndex(id); if (index >= 0) host.database.objects.items[index].privView = false; host.frameList.removeLast(); host.drawWorkFlowViewContentFunc(true); }); }; func.change_period = function(period){ hr.work_flows.changeObjectPeriod(host, id, period); }; func.editGeneralInformationFunc = function(){ hr.work_flows.editObjectPre(host, id); }; func.editExtraDataFunc = function(){ hr.work_flows.editExtraData(host, id); }; func.editEmployeeFunc = function(){ hr.work_flows.editObjectEmployee(host, id); }; func.addFromTemplateFunc = function(){ hr.work_flows.addFromEmployeeTemplatePre(host, id); }; func.createTemplateFunc = function(){ hr.work_flows.createEmployeeTemplate(host, id); }; func.addPartnerFunc = function(){ hr.work_flows.addPartnerPre(host, id); }; func.addContactFunc = function(){ hr.work_flows.addContactPre(host, id); }; } var load_history_func = function(){ return new Promise(function(rs, rj){ ModalElement.show_loading(); FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "object_load_history_by_id"}, {name: "id", value: id} ], func: function(success, message){ if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); st.sort(function(a, b){ return b.createdtime - a.createdtime; }); rs(st); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; host.userSendNotiList = []; host.objectCommentCtn = contentModule.drawComment({taskid: id, tablename: "objects", disabled: host.dataObjectEdit.closed, userSendNotiList: host.userSendNotiList, frameList: host.frameList}); var params = { id: id, work_flowid: host.work_flowid, viewType: host.viewType, quick_open: host.quick_open, cmdbutton: cmdbutton, frameList: host.frameList, holder: host.holder, host: host, data: host.dataObjectEdit, periodsList: host.periodsList, func: func, viewGeneralInformation: hr.work_flows.getGeneralInformationCtn(host, id), viewEmployee: hr.work_flows.getEmployeeCtn(host, id), viewPartner: hr.work_flows.getPartnerCtn(host, id), viewContact: hr.work_flows.getContactCtn(host, id), viewComment: host.objectCommentCtn, type_extra_of_object: host.dataWork_flowView.type_extra_of_object, load_history_func: function(){ return load_history_func(); } }; params.employeesFullnameDic = {}; for (var i = 0; i < host.database.employees.items.length; i++){ params.employeesFullnameDic[host.database.employees.items[i].userid] = host.database.employees.items[i].fullname; } if (host.dataWork_flowView.type_extra_of_object != 0){ params.viewExtraData = hr.work_flows.getExtraDataCtn(host, id); } host.layoutViewObject = theme.workFlowViewObject(params); host.redraw_history_func = params.redraw_history_func; contentModule.activitiesInformation({ workSelected: "both", tableName: "objects", instanceid: id, addActivitiesSelected: host.dataObjectEdit.privEdit? "normal" : "none", frameList: host.frameList }).then(function(result){ var chart = result.getChartContent(); host.layoutViewObject.chartCtn.appendChild(chart); var activities = result.getActivitiesContent(); host.layoutViewObject.activitiesCtn.appendChild(activities); if (param2 && param2.scroll == "comments"){ setTimeout(function(){ host.objectCommentCtn.scrollIntoView(); }, 100); } }); }; hr.work_flows.viewObjectsPre = function(host, id, param2){ ModalElement.show_loading(); if (host.quick_open){ data_module.loadEmployeeItemsPrivView().then(function(values){ host.database = values.database; host.orgsLoaded = true; FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "work_flows_load_objects_details_quick"}, {name: "id", value: id} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); host.employeeOfMe = st.employeeOfMe; delete st.employeeOfMe; contentModule.makeDatabaseContent(host, st); host.form_config = contentModule.configVariable(host); host.user_column_configsDic = contentModule.getUser_column_configsDic(host); contentModule.makePrivilegeViewWorkFlow(host); contentModule.makePrivilegeObjects(host); contentModule.makeUserMarkerData(host, "objects"); hr.work_flows.makePeriodsList(host); host.drawWorkFlowViewContentFunc = function(){ }; var index = host.database.objects.getIndex(id); if (index < 0 || !host.database.objects.items[index].privView){ ModalElement.alert({ message: LanguageModule.text("war_txt_no_privileges_with_objects"), func: function(){ hr.menu.tabPanel.removeTab(host.holder.id); } }); return; } host.dataObjectEdit = host.database.objects.items[index]; if (host.dataObjectEdit.attachments == "") host.dataObjectEdit.attachments = {}; else host.dataObjectEdit.attachments = EncodingClass.string.toVariable(host.dataObjectEdit.attachments); var index = host.database.work_flows.getIndex(host.dataObjectEdit.work_flowid); if (index < 0 || !host.database.work_flows.items[index].privView){ ModalElement.alert({ message: LanguageModule.text("war_txt_no_privileges_with_work_flows"), func: function(){ hr.menu.tabPanel.removeTab(host.holder.id); } }); return; } host.work_flowid = host.database.work_flows.items[0].id; host.dataWork_flowView = host.database.work_flows.items[0]; hr.work_flows.viewObjects(host, id, param2); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); } else { FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "work_flows_load_objects_details"}, {name: "id", value: id} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ host.dataObjectEdit = EncodingClass.string.toVariable(message.substr(2)); var index = host.database.objects.getIndex(id); if (host.dataObjectEdit.extrainfo == "") host.dataObjectEdit.extrainfo = {}; else host.dataObjectEdit.extrainfo = EncodingClass.string.toVariable(host.dataObjectEdit.extrainfo); if (host.dataObjectEdit.attachments == "") host.dataObjectEdit.attachments = {}; else host.dataObjectEdit.attachments = EncodingClass.string.toVariable(host.dataObjectEdit.attachments); host.dataObjectEdit.privEdit = host.database.objects.items[index].privEdit; host.dataObjectEdit.marked = host.database.objects.items[index].marked; hr.work_flows.viewObjects(host, id); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); } }; hr.work_flows.makePeriodsList = function(host){ if (!host.periodsList) host.periodsList = []; host.periodsList.length = 0 for (var i = 0; i < host.database.work_flow_periods.items.length; i++){ host.periodsList.push({ id: host.database.work_flow_periods.items[i].id, name: host.database.work_flow_periods.items[i].name, color: host.database.work_flow_periods.items[i].color, objectsList: [] }); } var periodsSystem = contentModule.getObjectPeriodSystemList(); for (var i = 0; i < periodsSystem.length; i++){ host.periodsList.push({ id: periodsSystem[i].id, name: periodsSystem[i].name, color: periodsSystem[i].color, isSystem: true, objectsList: [] }); } var periodsDic = contentModule.makeDictionaryIndex(host.periodsList); var pIndex; for (var i = 0; i < host.database.objects.items.length; i++){ if (!host.database.objects.items[i].privView) continue; host.database.objects.items[i].opening = !host.database.objects.items[i].closed; pIndex = periodsDic[host.database.objects.items[i].period]; if (pIndex >= 0){ host.periodsList[pIndex].objectsList.push(host.database.objects.items[i]); } } }; hr.work_flows.changePeriodForObject = function(host, objectid, period){ FormClass.api_call({ url: "work_flows_change_object_period.php", params: [{ name: "data", value: EncodingClass.string.fromVariable({ id: objectid, period: period }) }], func: function(success, message){ if (success){ if (message.substr(0, 2) == "ok"){ // TODO: var index = host.database.objects.getIndex(objectid); host.database.objects.items[index].period = period; hr.work_flows.makePeriodsList(host); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; hr.work_flows.deleteObject = function(host, id){ return new Promise(function(resolve, reject){ ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_delete_object.php", params: [ {name: "id", value: id} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var index = host.database.objects.getIndex(id); host.database.objects.items.splice(index, 1); hr.work_flows.makePeriodsList(host); resolve(); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.deleteObjectConfirm = function(host, id){ return new Promise(function(resolve, reject){ var index = host.database.objects.getIndex(id); ModalElement.question({ title: LanguageModule.text("war_title_delete_object"), message: LanguageModule.text2("war_txt_detele", [host.database.objects.items[index].name]), onclick: function(sel){ if (sel == 0){ hr.work_flows.deleteObject(host, id).then(function(value){ resolve(value); }); } } }); }); }; hr.work_flows.loadObjectClose = function(host, id){ return new Promise(function(resolve, reject){ if (!host.loadObjectDone){ setTimeout(function(){ hr.work_flows.loadObjectClose(host, id).then(function(values){ resolve(values); }); }, 50); return; } if (!host.objectClosedLoad){ FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "work_flows_load_objects_closed"}, {name: "work_flowid", value: id} ], func: function(success, message){ if (success){ if (message.substr(0, 2) == "ok"){ if (host.objectClosedLoad){ resolve(host.periodsList); return; } var st = EncodingClass.string.toVariable(message.substr(2)); var x = { employeeOfMe: host.employeeOfMe, database: { work_flow_admin_privileges: host.database.work_flow_admin_privileges, orgs: host.database.orgs, employees: host.database.employees } }; contentModule.makeDatabaseContent(x, st); host.database.object_permissions.items = host.database.object_permissions.items.concat(x.database.object_permissions.items); contentModule.makePrivilegeObjects(x); contentModule.makeObjectPermissionData(x); var objectsDic = contentModule.makeDictionaryIndex(host.database.objects.items); var objectsList = []; for (var i = 0; i < x.database.objects.items.length; i++){ if (!x.database.objects.items[i].privView) continue; if (objectsDic[x.database.objects.items[i].id] !== undefined) continue; objectsList.push({ id: x.database.objects.items[i].id, privView: x.database.objects.items[i].privView, privEdit: x.database.objects.items[i].privEdit, assign_to: x.database.objects.items[i].assign_to, employeeRelatedDic: x.database.objects.items[i].employeeRelatedDic }); } console.log(objectsList); hr.work_flows.loadObjectsListByIDList(host, objectsList).then(function(objects){ ModalElement.close(-1); for (var i = 0; i < objects.items.length; i++){ objects.items[i].opening = !objects.items[i].closed; host.database.objects.items.push(objects.items[i]); } hr.work_flows.makePeriodsList(host); host.objectClosedLoad = true; resolve(host.periodsList); }); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); } else { ModalElement.close(-1); resolve(host.periodsList); } }); }; hr.work_flows.filterSettingsSave = function(host, id, value){ return new Promise(function(resolve, reject){ ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_save_filter_settings.php", params: [ {name: "work_flowid", value: id}, {name: "config", value: EncodingClass.string.fromVariable(value)} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); host.database.work_flow_filter_configs.items = [st]; hr.work_flows.makeFilterConfigsList(host).then(function(value){ resolve(host.filterConfigList); }); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.changeTypeView = function(host, id, type_view){ FormClass.api_call({ url: "work_flows_change_type_view_save.php", params: [ {name: "work_flowid", value: id}, {name: "type_view", value: type_view} ], func: function(success, message){ if (success){ if (message.substr(0, 2) == "ok"){ var index = host.database.work_flows.getIndex(id); host.database.work_flows.items[index].default_open = type_view; } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; hr.work_flows.lazyLoadDataObjects = function(host){ if (host.loadObjectDone){ return; } if (!host.pageViewWorkflow) return; if (!host.pageViewWorkflow.insertDataFunc){ setTimeout(function(){ hr.work_flows.lazyLoadDataObjects(host); }, 50); return; } var objectsList = []; objectsList.push.apply(objectsList, host.objectsList.splice(0, 500)); host.loadObjectDone = host.objectsList.length == 0; hr.work_flows.loadObjectsListByIDList(host, objectsList).then(function(objects){ for (var i = 0; i < objects.items.length; i++){ if (!host.pageViewWorkflow || host.pageViewWorkflow.id != objects.items[i].work_flowid) return; objects.items[i].opening = !objects.items[i].closed; host.database.objects.items.push(objects.items[i]); } host.pageViewWorkflow.insertDataFunc(objects.items); hr.work_flows.lazyLoadDataObjects(host); }); }; hr.work_flows.changeEmployees = function(host, work_flowid){ ModalElement.show_loading(); Promise.all([hr.work_flows.objectsLoadPermissions(host, 0), hr.work_flows.makeFilterConfigsList(host, true)]).then(function(values){ var employeeData = values[0]; ModalElement.close(-1); var navItems = [ {text: LanguageModule.text("txt_filter_objects")}, {text: LanguageModule.text("txt_replace_employees")}, {text: LanguageModule.text("txt_add_employees")}, {text: LanguageModule.text("txt_finished")} ]; var vTimeline = absol.buildDom({ tag: 'verticaltimeline', props: { items: navItems } }); var filterElt = DOMElement.div({}); var filterBoxes = {}; for (var i = 0; i < host.filterConfigList.length; i++){ // if (!host.filterConfigList[i].display) continue; if (host.filterConfigList[i].tree_leaf){ filterBoxes[host.filterConfigList[i].name] = absol.buildDom({ tag: "selecttreeleafmenu", style: { display: "block", width: "100%" }, props: { items: host.filterConfigList[i].itemsList, value: host.filterConfigList[i].value, enableSearch: true } }); } else if (host.filterConfigList[i].tree){ filterBoxes[host.filterConfigList[i].name] = absol.buildDom({ tag: "selecttreemenu", style: { display: "block", width: "100%" }, props: { items: host.filterConfigList[i].itemsList, value: host.filterConfigList[i].value, enableSearch: true } }); } else if (host.filterConfigList[i].nation_city){ filterBoxes[host.filterConfigList[i].name] = absol.buildDom({ tag: "dualselectmenu", style: { display: "block", width: "100%" }, props: { items: host.filterConfigList[i].itemsList, value: host.filterConfigList[i].value, enableSearch: true } }); } else { filterBoxes[host.filterConfigList[i].name] = absol.buildDom({ tag: "selectmenu", style: { display: "block", width: "100%" }, props: { items: host.filterConfigList[i].itemsList, value: host.filterConfigList[i].value, enableSearch: true }, on: { change: function(i){ return function(){ if (host.filterConfigList[i].name == "opening"){ hr.work_flows.loadObjectClose(host, work_flowid); } } }(i) } }); } filterElt.appendChild(DOMElement.div({ attrs: { className: "card-mobile-label-form-edit" }, text: host.filterConfigList[i].text })); filterElt.appendChild(filterBoxes[host.filterConfigList[i].name]); } var filterPageCtn = DOMElement.div({ attrs: { className: 'kv-document-2-site-right kv-document-page' }, children: [ absol.buildDom({ class: 'kv-document-page-header', child: [ { tag: 'span', class: 'kv-document-page-title', child: { text: LanguageModule.text("txt_filter_objects") } }, { tag: 'button', class: ['kv-document-transparent-btn', 'kv-document-page-close-btn'], child: 'span.mdi.mdi-close', on: { click: function(){ ModalElement.close(); } } } ] }), DOMElement.div({ attrs: {className: "kv-document-page-content"}, children: [ DOMElement.div({ attrs: {style: {height: "var(--control-height)", lineHeight: "var(--control-height)", fontWeight: "bold"}}, text: LanguageModule.text("txt_set_objects_filters_to_change_employees") }), filterElt ] }), absol.buildDom({ class: 'kv-document-page-footer', child: [ DOMElement.div({attrs: {className: "kv-document-page-footer-left"}}), DOMElement.div({ attrs: {className: "kv-document-page-footer-right"}, children: [ theme.noneIconButton({ className: "primary", text: LanguageModule.text("txt_next"), onclick: function(){ vTimeline.current = 1; filterPageCtn.style.display = "none"; replacePageCtn.style.display = ""; } }), DOMElement.div({ attrs: { className: "kv-document-link", onclick: function(){ ModalElement.close(); } }, text: LanguageModule.text("txt_cancel") }) ] }) ] }) ] }); employeeData.items_assign_to_List.unshift({value: 0, text: LanguageModule.text("txt_select_value"), isLeaf: true}); var find_assign_to_select = absol.buildDom({ tag: "selecttreeleafmenu", props: { items: employeeData.items_assign_to_List, enableSearch: true } }); var replace_assign_to_select = absol.buildDom({ tag: "selecttreeleafmenu", props: { items: employeeData.items_assign_to_List, enableSearch: true } }); var find_view_select = absol.buildDom({ tag: "selecttreeleafmenu", props: { items: employeeData.items_assign_to_List, enableSearch: true } }); var replace_view_select = absol.buildDom({ tag: "selecttreeleafmenu", props: { items: employeeData.items_assign_to_List, enableSearch: true } }); var find_edit_select = absol.buildDom({ tag: "selecttreeleafmenu", props: { items: employeeData.items_assign_to_List, enableSearch: true } }); var replace_edit_select = absol.buildDom({ tag: "selecttreeleafmenu", props: { items: employeeData.items_assign_to_List, enableSearch: true } }); var replacePageCtn = DOMElement.div({ attrs: { className: 'kv-document-2-site-right kv-document-page', style: {display: "none"} }, children: [ absol.buildDom({ class: 'kv-document-page-header', child: [ { tag: 'span', class: 'kv-document-page-title', child: { text: LanguageModule.text("txt_replace_employees") } }, { tag: 'button', class: ['kv-document-transparent-btn', 'kv-document-page-close-btn'], child: 'span.mdi.mdi-close', on: { click: function(){ ModalElement.close(); } } } ] }), DOMElement.div({ attrs: { className: 'kv-document-page-content' }, children: [ DOMElement.div({ attrs: {style: {height: "var(--control-height)", lineHeight: "var(--control-height)", fontWeight: "bold"}}, text: LanguageModule.text("txt_set_rules_to_replace_employees") }), DOMElement.table({ data: [ [{ attrs: {colSpan: 3, style: {fontWeight: "bold"}}, text: LanguageModule.text("txt_assigned_employee") }], [{attrs: {style: {height: "20px"}}}], [ {text: LanguageModule.text("txt_find")}, {attrs: {style: {width: "var(--control-horizontal-distance-2)"}}}, find_assign_to_select ], [{attrs: {style: {height: "var(--control-verticle-distance-2)"}}}], [ {text: LanguageModule.text("txt_replace")}, {attrs: {style: {width: "var(--control-horizontal-distance-2)"}}}, replace_assign_to_select ], [{attrs: {style: {height: "20px"}}}], [{ attrs: {colSpan: 3, style: {fontWeight: "bold"}}, text: LanguageModule.text("txt_employee_has_permission_view") }], [{attrs: {style: {height: "var(--control-verticle-distance-2)"}}}], [ {text: LanguageModule.text("txt_find")}, {attrs: {style: {width: "var(--control-horizontal-distance-2)"}}}, find_view_select ], [{attrs: {style: {height: "var(--control-verticle-distance-2)"}}}], [ {text: LanguageModule.text("txt_replace")}, {attrs: {style: {width: "var(--control-horizontal-distance-2)"}}}, replace_view_select ], [{attrs: {style: {height: "20px"}}}], [{ attrs: {colSpan: 3, style: {fontWeight: "bold"}}, text: LanguageModule.text("txt_employee_has_permission_edit") }], [{attrs: {style: {height: "var(--control-verticle-distance-2)"}}}], [ {text: LanguageModule.text("txt_find")}, {attrs: {style: {width: "var(--control-horizontal-distance-2)"}}}, find_edit_select ], [{attrs: {style: {height: "var(--control-verticle-distance-2)"}}}], [ {text: LanguageModule.text("txt_replace")}, {attrs: {style: {width: "var(--control-horizontal-distance-2)"}}}, replace_edit_select ] ] }) ] }), absol.buildDom({ class: 'kv-document-page-footer', child: [ DOMElement.div({ attrs: {className: "kv-document-page-footer-left"}, children: [ theme.noneIconButton({ text: LanguageModule.text("txt_back"), onclick: function(){ vTimeline.current = 0; filterPageCtn.style.display = ""; replacePageCtn.style.display = "none"; } }) ] }), DOMElement.div({ attrs: {className: "kv-document-page-footer-right"}, children: [ theme.noneIconButton({ className: "primary", text: LanguageModule.text("txt_next"), onclick: function(){ var find_assign_to = find_assign_to_select.value; var replace_assign_to = replace_assign_to_select.value; if (find_assign_to == 0 && replace_assign_to != 0){ ModalElement.alert({message: LanguageModule.text("war_txt_you_havent_input_assigned_employee_to_find")}); return; } if (find_assign_to != 0 && replace_assign_to == 0){ ModalElement.alert({message: LanguageModule.text("war_txt_you_havent_input_assigned_employee_to_replace")}); return; } if (find_assign_to == replace_assign_to && find_assign_to != 0){ ModalElement.alert({message: LanguageModule.text("war_txt_employee_to_find_must_different_from_employee_to_replace")}); return; } var find_view = find_view_select.value; var replace_view = replace_view_select.value; if (find_view == 0 && replace_view != 0){ ModalElement.alert({message: LanguageModule.text("war_txt_you_havent_input_employee_has_view_permission_to_find")}); return; } if (find_view != 0 && replace_view == 0){ ModalElement.alert({message: LanguageModule.text("war_txt_you_havent_input_employee_has_view_permission_to_replace")}); return; } if (find_view == replace_view && replace_view != 0){ ModalElement.alert({message: LanguageModule.text("war_txt_employee_to_find_must_different_from_employee_to_replace")}); return; } var find_edit = find_edit_select.value; var replace_edit = replace_edit_select.value; if (find_edit == 0 && replace_edit != 0){ ModalElement.alert({message: LanguageModule.text("war_txt_you_havent_input_employee_has_edit_permission_to_find")}); return; } if (find_edit != 0 && replace_edit == 0){ ModalElement.alert({message: LanguageModule.text("war_txt_you_havent_input_employee_has_edit_permission_to_replace")}); return; } if (find_edit == replace_edit && replace_edit != 0){ ModalElement.alert({message: LanguageModule.text("war_txt_employee_to_find_must_different_from_employee_to_replace")}); return; } vTimeline.current = 2; replacePageCtn.style.display = "none"; addPageCtn.style.display = ""; } }), DOMElement.div({ attrs: { className: "kv-document-link", onclick: function(){ ModalElement.close(); } }, text: LanguageModule.text("txt_cancel") }) ] }) ] }) ] }); var add_view_select = absol.buildDom({ tag: "multichecktreemenu", props: { items: employeeData.itemsList, enableSearch: true } }); var add_edit_select = absol.buildDom({ tag: "multichecktreemenu", props: { items: employeeData.itemsList, enableSearch: true } }); var addPageCtn = DOMElement.div({ attrs: { className: 'kv-document-2-site-right kv-document-page', style: {display: "none"} }, children: [ absol.buildDom({ class: 'kv-document-page-header', child: [ { tag: 'span', class: 'kv-document-page-title', child: { text: LanguageModule.text("txt_add_employees") } }, { tag: 'button', class: ['kv-document-transparent-btn', 'kv-document-page-close-btn'], child: 'span.mdi.mdi-close', on: { click: function(){ ModalElement.close(); } } } ] }), DOMElement.div({ attrs: { className: 'kv-document-page-content' }, children: [ DOMElement.table({ data: [ [{ attrs: {colSpan: 3, style: {fontWeight: "bold"}}, text: LanguageModule.text("txt_add_employee_to_objects") }], [{attrs: {style: {height: "20px"}}}], [ {text: LanguageModule.text("txt_employee_has_permission_view")}, {attrs: {style: {width: "var(--control-horizontal-distance-2)"}}}, add_view_select ], [{attrs: {style: {height: "var(--control-verticle-distance-2)"}}}], [ {text: LanguageModule.text("txt_employee_has_permission_edit")}, {attrs: {style: {width: "var(--control-horizontal-distance-2)"}}}, add_edit_select ] ] }) ] }), absol.buildDom({ class: 'kv-document-page-footer', child: [ DOMElement.div({ attrs: {className: "kv-document-page-footer-left"}, children: [ theme.noneIconButton({ text: LanguageModule.text("txt_back"), onclick: function(){ vTimeline.current = 0; replacePageCtn.style.display = ""; addPageCtn.style.display = "none"; } }) ] }), DOMElement.div({ attrs: {className: "kv-document-page-footer-right"}, children: [ theme.noneIconButton({ className: "primary", text: LanguageModule.text("txt_start"), onclick: function(){ var saveFunc = function(){ if (!host.loadObjectDone){ setTimeout(function(){ saveFunc(); }, 50); return; } for (var i = 0; i < host.filterConfigList.length; i++){ if (!host.filterConfigList[i].display) continue; if (host.filterConfigList[i].name == "opening" && filterBoxes[host.filterConfigList[i].name].value != 1){ if (!host.objectClosedLoad){ setTimeout(function(){ saveFunc(); }, 50); return; } } } var objectsIDList = []; host.database.objects.items.forEach(function(objectItem){ var view = true, value; if (!objectItem.privEdit) view = false; else { for (var j = 0; j < host.filterConfigList.length; j++){ // if (!host.filterConfigList[j].display) continue; if (filterBoxes[host.filterConfigList[j].name].value == "all") continue; if (host.filterConfigList[j].name == "related_person"){ if (!objectItem.employeeRelatedDic[filterBoxes[host.filterConfigList[j].name].value]) view = false; } else { if (host.filterConfigList[j].extra){ value = objectItem.extra_data[host.filterConfigList[j].name]; } else { if (host.filterConfigList[j].main){ value = objectItem[host.filterConfigList[j].name]; } else { value = objectItem.extrainfo[host.filterConfigList[j].name]; } } if (host.filterConfigList[j].nation_city){ if (host.filterConfigList[j].value[0] == 0) continue; if (host.filterConfigList[j].value[1] == 0){ if (!EncodingClass.type.isArray(value) || value[0] != host.filterConfigList[j].value[0]){ view = false; break; } } else { if (!EncodingClass.type.isArray(value) || value[1] != host.filterConfigList[j].value[1]){ view = false; break; } } } else { if (filterBoxes[host.filterConfigList[j].name].value != value){ view = false; break; } } } } } if (view) objectsIDList.push(objectItem.id); }); if (objectsIDList.length == 0){ ModalElement.close(-1); DOMElement.removeAllChildren(finishElt); finishElt.appendChild(DOMElement.span({ text: LanguageModule.text2("txt_you_changed_employee_for_objects", [0]) })); vTimeline.current = 3; addPageCtn.style.display = "none"; finishPageCtn.style.display = ""; return; } objectsIDList.sort(function(a, b){ return a - b; }); var data = { objectsIDList: objectsIDList, find_assign_to: find_assign_to, replace_assign_to: replace_assign_to, find_view: find_view, replace_view: replace_view, find_edit: find_edit, replace_edit: replace_edit, add_view: add_view, add_edit: add_edit }; FormClass.api_call({ url: "work_flows_change_employees.php", params: [{name: "data", value: EncodingClass.string.fromVariable(data)}], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var count = parseInt(message.substr(2), 10); DOMElement.removeAllChildren(finishElt); finishElt.appendChild(DOMElement.span({ text: LanguageModule.text2("txt_you_changed_employee_for_objects", [count]) })); vTimeline.current = 3; addPageCtn.style.display = "none"; finishPageCtn.style.display = ""; var objectsDic = contentModule.makeDictionaryIndex(host.database.objects.items); if (replace_assign_to != 0){ var k; for (var i = 0; i < objectsIDList.length; i++){ k = objectsDic[objectsIDList[i]]; if (k >= 0 && host.database.objects.items[k].assign_to == find_assign_to){ host.database.objects.items[k].assign_to = replace_assign_to; } } host.drawWorkFlowViewContentFunc(); } setTimeout(function(){ FormClass.api_call({ url: "work_flows_delete_object_permissions_residual.php", params: [], func: function(success, message){ console.log(success, message); } }); }, 30000); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; var find_assign_to = find_assign_to_select.value; var replace_assign_to = replace_assign_to_select.value; var find_view = find_view_select.value; var replace_view = replace_view_select.value; var find_edit = find_edit_select.value; var replace_edit = replace_edit_select.value; var ischange = false; if (find_assign_to != 0 || find_view != 0 || find_edit != 0) ischange = true; var add_view = add_view_select.values; var add_edit = add_edit_select.values; if (add_view.length > 0 || add_edit.length > 0) ischange = true; if (!ischange){ ModalElement.alert({message: LanguageModule.text("war_txt_you_havent_set_any_rules_to_replace_or_add_employees")}); return; } ModalElement.show_loading(); saveFunc(); } }), DOMElement.div({ attrs: { className: "kv-document-link", onclick: function(){ ModalElement.close(); } }, text: LanguageModule.text("txt_cancel") }) ] }) ] }) ] }); var finishElt = DOMElement.div({attrs: {align: "center", paddingTop: "50px", fontWeight: "bold"}}); var finishPageCtn = DOMElement.div({ attrs: { className: 'kv-document-2-site-right kv-document-page', style: {display: "none"} }, children: [ absol.buildDom({ class: 'kv-document-page-header', child: [ { tag: 'span', class: 'kv-document-page-title', child: { text: LanguageModule.text("txt_finished") } }, { tag: 'button', class: ['kv-document-transparent-btn', 'kv-document-page-close-btn'], child: 'span.mdi.mdi-close', on: { click: function(){ ModalElement.close(); } } } ] }), DOMElement.div({ attrs: { className: 'kv-document-page-content' }, children: [finishElt] }), absol.buildDom({ class: 'kv-document-page-footer', child: [ DOMElement.div({ attrs: {className: "kv-document-page-footer-left"} }), DOMElement.div({ attrs: {className: "kv-document-page-footer-right"}, children: [ theme.noneIconButton({ className: "primary", text: LanguageModule.text("txt_close"), onclick: function(){ ModalElement.close(); } }) ] }) ] }) ] }); ModalElement.show({ bodycontent: absol.buildDom({ class: 'kv-document-2-site', style: { minWidth: "50vw", height: "70vh" }, child: [ { class: 'kv-document-2-site-left', child: [ { class: 'kv-document-2-site-left-header', child: [ { tag: 'span', class: 'kv-document-2-site-left-header-text', child: { text: LanguageModule.text("txt_change_employees") } } ] }, vTimeline ] }, filterPageCtn, replacePageCtn, addPageCtn, finishPageCtn ] }) }); }); }; hr.work_flows.massInput = function(host, work_flowid){ ModalElement.show_loading(); Promise.all([hr.work_flows.objectsLoadPermissions(host, 0), hr.work_flows.makeFilterConfigsList(host, true)]).then(function(values){ var employeeData = values[0]; ModalElement.close(-1); var navItems = [ {text: LanguageModule.text("txt_filter_objects")}, {text: LanguageModule.text("txt_input_data")}, {text: LanguageModule.text("txt_finished")} ]; var vTimeline = absol.buildDom({ tag: 'verticaltimeline', props: { items: navItems } }); var filterElt = DOMElement.div({}); var filterBoxes = {}; for (var i = 0; i < host.filterConfigList.length; i++){ // if (!host.filterConfigList[i].display) continue; if (host.filterConfigList[i].tree_leaf){ filterBoxes[host.filterConfigList[i].name] = absol.buildDom({ tag: "selecttreeleafmenu", style: { display: "block", width: "100%" }, props: { items: host.filterConfigList[i].itemsList, value: host.filterConfigList[i].value, enableSearch: true } }); console.log(host.filterConfigList[i].value); } else if (host.filterConfigList[i].tree){ filterBoxes[host.filterConfigList[i].name] = absol.buildDom({ tag: "selecttreemenu", style: { display: "block", width: "100%" }, props: { items: host.filterConfigList[i].itemsList, value: host.filterConfigList[i].value, enableSearch: true } }); } else if (host.filterConfigList[i].nation_city){ filterBoxes[host.filterConfigList[i].name] = absol.buildDom({ tag: "dualselectmenu", style: { display: "block", width: "100%" }, props: { items: host.filterConfigList[i].itemsList, value: host.filterConfigList[i].value, enableSearch: true } }); } else { filterBoxes[host.filterConfigList[i].name] = absol.buildDom({ tag: "selectmenu", style: { display: "block", width: "100%" }, props: { items: host.filterConfigList[i].itemsList, value: host.filterConfigList[i].value, enableSearch: true }, on: { change: function(i){ return function(){ if (host.filterConfigList[i].name == "opening"){ hr.work_flows.loadObjectClose(host, work_flowid); } } }(i) } }); } filterElt.appendChild(DOMElement.div({ attrs: { className: "card-mobile-label-form-edit" }, text: host.filterConfigList[i].text })); filterElt.appendChild(filterBoxes[host.filterConfigList[i].name]); } var filterPageCtn = DOMElement.div({ attrs: { className: 'kv-document-2-site-right kv-document-page' }, children: [ absol.buildDom({ class: 'kv-document-page-header', child: [ { tag: 'span', class: 'kv-document-page-title', child: { text: LanguageModule.text("txt_filter_objects") } }, { tag: 'button', class: ['kv-document-transparent-btn', 'kv-document-page-close-btn'], child: 'span.mdi.mdi-close', on: { click: function(){ ModalElement.close(); } } } ] }), DOMElement.div({ attrs: {className: "kv-document-page-content"}, children: [ DOMElement.div({ attrs: {style: {height: "var(--control-height)", lineHeight: "var(--control-height)", fontWeight: "bold"}}, text: LanguageModule.text("txt_set_objects_filters_to_mass_input") }), filterElt ] }), absol.buildDom({ class: 'kv-document-page-footer', child: [ DOMElement.div({attrs: {className: "kv-document-page-footer-left"}}), DOMElement.div({ attrs: {className: "kv-document-page-footer-right"}, children: [ theme.noneIconButton({ className: "primary", text: LanguageModule.text("txt_next"), onclick: function(){ vTimeline.current = 1; filterPageCtn.style.display = "none"; inputDataPageCtn.style.display = ""; } }), DOMElement.div({ attrs: { className: "kv-document-link", onclick: function(){ ModalElement.close(); } }, text: LanguageModule.text("txt_cancel") }) ] }) ] }) ] }); var typeDic = contentModule.makeDictionaryIndex(host.database.typelists.items); var items = [{value: 0, text: LanguageModule.text("txt_select_value")}]; if (host.dataWork_flowView.type_extra_of_object != 0){ var columnList = contentModule.getColumnListFromTypeid(host, host.dataWork_flowView.type_extra_of_object, {}, true); columnList.forEach(function(item){ var tIndex = typeDic[item.type]; var type = host.database.typelists.items[tIndex].type; if (type == "enum" || type == "extends_enum" || host.database.typelists.items[tIndex].type2 == "enum"){ items.push({ value: item.value, text: item.text }); } }); } var field_select = absol.buildDom({ tag: "selectmenu", props: { items: items, enableSearch: true }, on: { change: function(){ var itemsList = [{value: 0, text: LanguageModule.text("txt_select_value")}]; if (this.value != 0){ var t; for (var i = 0; i < columnList.length; i++){ if (columnList[i].value == this.value){ t = columnList[i].type; } } if (t){ var x = []; contentModule.getDetailsExtends(host, x, t); for (var i = 0; i < x.length; i++){ itemsList.push({value: x[i].localid, text: x[i].text}); } } } DOMElement.removeAllChildren(data_ctn); var elt = absol.buildDom({ tag: "selectmenu", props: { items: itemsList, enableSearch: true } }); data_ctn.appendChild(elt); data_ctn.getValue = function(){ var value = elt.value; if (value == 0){ ModalElement.alert({message: "Chưa chọn giá trị"}); return; } var text; for (var i = 0; i < elt.items.length; i++){ if (elt.items[i].value == value){ text = elt.items[i].text; break; } } return { value: value, text: text }; }; } } }); var data_ctn = DOMElement.div({}); var inputDataPageCtn = DOMElement.div({ attrs: { className: 'kv-document-2-site-right kv-document-page', style: {display: "none"} }, children: [ absol.buildDom({ class: 'kv-document-page-header', child: [ { tag: 'span', class: 'kv-document-page-title', child: { text: LanguageModule.text("txt_input_data") } }, { tag: 'button', class: ['kv-document-transparent-btn', 'kv-document-page-close-btn'], child: 'span.mdi.mdi-close', on: { click: function(){ ModalElement.close(); } } } ] }), DOMElement.div({ attrs: { className: 'kv-document-page-content' }, children: [ DOMElement.table({ data: [ [ {text: "Trường thay đổi"}, {attrs: {style: {width: "var(--control-horizontal-distance-2)"}}}, field_select ], [{attrs: {style: {height: "var(--control-verticle-distance-2)"}}}], [ {text: "Dữ liệu"}, {attrs: {style: {width: "var(--control-horizontal-distance-2)"}}}, data_ctn ] ] }) ] }), absol.buildDom({ class: 'kv-document-page-footer', child: [ DOMElement.div({ attrs: {className: "kv-document-page-footer-left"}, children: [ theme.noneIconButton({ text: LanguageModule.text("txt_back"), onclick: function(){ vTimeline.current = 0; filterPageCtn.style.display = ""; inputDataPageCtn.style.display = "none"; } }) ] }), DOMElement.div({ attrs: {className: "kv-document-page-footer-right"}, children: [ theme.noneIconButton({ className: "primary", text: LanguageModule.text("txt_start"), onclick: function(){ var saveFunc = function(){ if (!host.loadObjectDone){ setTimeout(function(){ saveFunc(); }, 50); return; } for (var i = 0; i < host.filterConfigList.length; i++){ if (!host.filterConfigList[i].display) continue; if (host.filterConfigList[i].name == "opening" && filterBoxes[host.filterConfigList[i].name].value != 1){ if (!host.objectClosedLoad){ setTimeout(function(){ saveFunc(); }, 50); return; } } } var objectsIDList = []; host.database.objects.items.forEach(function(objectItem){ var view = true, value; if (!objectItem.privEdit){ view = false; } else { for (var j = 0; j < host.filterConfigList.length; j++){ // if (!host.filterConfigList[j].display) continue; if (filterBoxes[host.filterConfigList[j].name].value == "all") continue; if (host.filterConfigList[j].name == "related_person"){ if (!objectItem.employeeRelatedDic[filterBoxes[host.filterConfigList[j].name].value]) view = false; } else { if (host.filterConfigList[j].extra){ value = objectItem.extra_data[host.filterConfigList[j].name]; } else { if (host.filterConfigList[j].main){ value = objectItem[host.filterConfigList[j].name]; } else { value = objectItem.extrainfo[host.filterConfigList[j].name]; } } if (host.filterConfigList[j].nation_city){ if (host.filterConfigList[j].value[0] == 0) continue; if (host.filterConfigList[j].value[1] == 0){ if (!EncodingClass.type.isArray(value) || value[0] != host.filterConfigList[j].value[0]){ view = false; break; } } else { if (!EncodingClass.type.isArray(value) || value[1] != host.filterConfigList[j].value[1]){ view = false; break; } } } else { if (filterBoxes[host.filterConfigList[j].name].value != value){ view = false; break; } } } } } if (view) objectsIDList.push(objectItem.id); }); if (objectsIDList.length == 0){ ModalElement.close(-1); DOMElement.removeAllChildren(finishElt); finishElt.appendChild(DOMElement.span({ text: LanguageModule.text2("txt_you_mass_input_for_objects", [0]) })); vTimeline.current = 2; inputDataPageCtn.style.display = "none"; finishPageCtn.style.display = ""; return; } objectsIDList.sort(function(a, b){ return a - b; }); var data = { objectsIDList: objectsIDList, input_data: input_data.input, field: input_data.field }; if (host.dataWork_flowView.type_extra_of_object != 0){ var typeDict = {}; host.database.typelists.items.forEach(function(elt){ typeDict[elt.id] = elt; }); data.defaultData = contentModule.makeDefaultData(host, host.dataWork_flowView.type_extra_of_object, typeDict[host.dataWork_flowView.type_extra_of_object], typeDict); data.defaultData[field] = input_data; } var dataLogs = { field_text: input_data.field_text, input_data_text: input_data.input_text, input_data: input_data.input, field: input_data.field, typeid: host.dataWork_flowView.type_extra_of_object }; FormClass.api_call({ url: "work_flows_mass_input.php", params: [ {name: "data", value: EncodingClass.string.fromVariable(data)}, {name: "dataLogs", value: EncodingClass.string.fromVariable(dataLogs)} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var count = parseInt(message.substr(2), 10); DOMElement.removeAllChildren(finishElt); finishElt.appendChild(DOMElement.span({ text: LanguageModule.text2("txt_you_mass_input_for_objects", [objectsIDList.length]) })); vTimeline.current = 2; inputDataPageCtn.style.display = "none"; finishPageCtn.style.display = ""; var objectsDic = contentModule.makeDictionaryIndex(host.database.objects.items); var k; for (var i = 0; i < objectsIDList.length; i++){ k = objectsDic[objectsIDList[i]]; if (k >= 0){ if (host.database.objects.items[k].extra_data){ host.database.objects.items[k].extra_data[field] = input_data; } else { host.database.objects.items[k].extra_data = data.defaultData; } } } host.drawWorkFlowViewContentFunc(); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; var field = field_select.value; if (field == 0){ ModalElement.alert({message: "Chưa chọn trường dữ liệu"}); return; } var field_text; for (var i = 0; i < field_select.items.length; i++){ if (field_select.items[i].value == field){ field_text = field_select.items[i].text; break; } } var input_data = data_ctn.getValue(); if (!input_data) return; input_data = { field: field, field_text: field_text, input: input_data.value, input_text: input_data.text }; ModalElement.show_loading(); saveFunc(); } }), DOMElement.div({ attrs: { className: "kv-document-link", onclick: function(){ ModalElement.close(); } }, text: LanguageModule.text("txt_cancel") }) ] }) ] }) ] }); var finishElt = DOMElement.div({attrs: {align: "center", paddingTop: "50px", fontWeight: "bold"}}); var finishPageCtn = DOMElement.div({ attrs: { className: 'kv-document-2-site-right kv-document-page', style: {display: "none"} }, children: [ absol.buildDom({ class: 'kv-document-page-header', child: [ { tag: 'span', class: 'kv-document-page-title', child: { text: LanguageModule.text("txt_finished") } }, { tag: 'button', class: ['kv-document-transparent-btn', 'kv-document-page-close-btn'], child: 'span.mdi.mdi-close', on: { click: function(){ ModalElement.close(); } } } ] }), DOMElement.div({ attrs: { className: 'kv-document-page-content' }, children: [finishElt] }), absol.buildDom({ class: 'kv-document-page-footer', child: [ DOMElement.div({ attrs: {className: "kv-document-page-footer-left"} }), DOMElement.div({ attrs: {className: "kv-document-page-footer-right"}, children: [ theme.noneIconButton({ className: "primary", text: LanguageModule.text("txt_close"), onclick: function(){ ModalElement.close(); } }) ] }) ] }) ] }); ModalElement.show({ bodycontent: absol.buildDom({ class: 'kv-document-2-site', style: { minWidth: "50vw", height: "70vh" }, child: [ { class: 'kv-document-2-site-left', child: [ { class: 'kv-document-2-site-left-header', child: [ { tag: 'span', class: 'kv-document-2-site-left-header-text', child: { text: LanguageModule.text("txt_mass_input") } } ] }, vTimeline ] }, filterPageCtn, inputDataPageCtn, finishPageCtn ] }) }); }); }; hr.work_flows.showWorkFlow = function(host, id, viewType){ return new Promise(function(resolveMn, rejectMn){ var index = host.database.work_flows.getIndex(id); if (index < 0 || !host.database.work_flows.items[index].privView){ ModalElement.alert({message: LanguageModule.text("war_txt_no_privileges_with_work_flows")}); return; } host.work_flowid = id; host.objectClosedLoad = false; host.viewType = viewType; var redraw = function(){ hr.work_flows.loadAllDataOfWorkFlow(host, id).then(function(value){ ModalElement.close(-1); var cmdbutton = {}; if (host.employeeOfMe.length > 0){ cmdbutton.add_object = function(){ hr.work_flows.addObjects(host); }; } if (systemconfig.privSystem >= 2){ cmdbutton.change_employees = function(){ hr.work_flows.changeEmployees(host, host.work_flowid); }; cmdbutton.mass_input = function(){ hr.work_flows.massInput(host, host.work_flowid); }; } hr.work_flows.makePeriodsList(host); host.pageViewWorkflow = theme.workFlowsViewForm({ frameList: host.frameList, holder: host.holder, filterConfigList: host.filterConfigList, database: host.database, form_config: host.form_config, user_column_configsDic: host.user_column_configsDic, data: host.dataWork_flowView, periodsList: host.periodsList, viewType: viewType, onlyViewTable: host.onlyViewTable, cmdbutton: cmdbutton, type_extra_of_object: host.database.work_flows.items[index].type_extra_of_object, func: { close_view_func: function(){ delete host.pageViewWorkflow; }, view_objects: function(id){ hr.work_flows.viewObjectsPre(host, id); }, delete: function(id){ return hr.work_flows.deleteObjectConfirm(host, id); }, close_object: function(id){ hr.work_flows.closeObject(host, id).then(function rs(){ host.drawWorkFlowViewContentFunc(); }, function rj(){ var index = host.database.objects.getIndex(id); if (index >= 0) host.database.objects.items[index].privView = false; host.drawWorkFlowViewContentFunc(); }); }, markedWorkFlowFunc: function(marked){ return new Promise(function(rs, rj){ contentModule.markedFunc(host, { id: host.work_flowid, marked: marked, task: "work_flows", tablename: "work_flows" }).then(function(v){ hr.work_flows.redraw(host); rs(v); }); }); }, markedObjectFunc: function(id, marked){ return contentModule.markedFunc(host, { id: id, marked: marked, task: "objects", tablename: "objects" }); }, change_period_for_object: function(objectid, period){ hr.work_flows.changePeriodForObject(host, objectid, period); }, filterChangeFunc: function(){ ModalElement.show_loading(); return hr.work_flows.loadObjectClose(host, id); }, filterSettingsSave: function(value){ return hr.work_flows.filterSettingsSave(host, id, value); }, change_type_view: function(type_view){ hr.work_flows.changeTypeView(host, id, type_view); } } }); host.pageViewWorkflow.id = host.work_flowid; hr.work_flows.lazyLoadDataObjects(host); host.drawWorkFlowViewContentFunc = function(changeUrl){ hr.work_flows.makePeriodsList(host); host.pageViewWorkflow.redrawFunc(host.periodsList, changeUrl); }; resolveMn(host); }); }; ModalElement.show_loading(); if (host.orgsLoaded){ redraw(); } else { ModalElement.show_loading(); data_module.loadEmployeeItemsPrivView().then(function(values){ for (var x in values.database){ host.database[x] = values.database[x]; } host.orgsLoaded = true; redraw(); }); } }); }; hr.work_flows.editWork_flowSubmit = function(host, id, getValueFunction){ return new Promise(function(resolve, reject){ var data = getValueFunction(); if (!data) return; var oldData = host.dataWork_flowEdit; var ischange = contentModule.isChanged(oldData, data, ["name", "groupid", "description", "type_extra_of_object", "input_form_extra_of_object", "output_form_extra_of_object", "mobile_input_form_extra_of_object", "mobile_output_form_extra_of_object", "available"] ); if (!ischange){ resolve(); return; } if (data.type_extra_of_object != 0){ if (data.input_form_extra_of_object == 0){ ModalElement.alert({message: LanguageModule.text("war_txt_input_form_is_null")}); return; } if (data.output_form_extra_of_object == 0){ ModalElement.alert({message: LanguageModule.text("war_txt_output_form_is_null")}); return; } if (data.mobile_input_form_extra_of_object == 0){ ModalElement.alert({message: LanguageModule.text("war_txt_mobile_input_form_is_null")}); return; } if (data.mobile_output_form_extra_of_object == 0){ ModalElement.alert({message: LanguageModule.text("war_txt_mobile_output_form_is_null")}); return; } } for (var i = 0; i < host.database.work_flows.items.length; i++){ if (host.database.work_flows.items[i].id == id) continue; if (host.database.work_flows.items[i].name == data.name){ ModalElement.alert({message: LanguageModule.text("war_txt_exist_name")}); return; } } delete data.typeid_of_object; data.id = id; data.available = data.available? 1 : 0; var index = host.database.work_flows.getIndex(id); data.ver = host.dataWork_flowEdit.ver; data.extrainfo = EncodingClass.string.fromVariable(data.extrainfo); ModalElement.show_loading(); FormClass.api_call({ url: "work_flow_save.php", params: [{name: "data", value: EncodingClass.string.fromVariable(data)}], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); st.extrainfo = EncodingClass.string.toVariable(st.extrainfo); st.privView = true; var index = host.database.work_flows.getIndex(id); st.marked = host.database.work_flows.items[index].marked; st.default_open = host.database.work_flows.items[index].default_open; host.database.work_flows.items[index] = st; host.dataWork_flowEdit = host.database.work_flows.items[index]; host.drawGeneralInforFunc(); hr.work_flows.redraw(host); resolve(); } else if (message == "lock_system"){ ModalElement.alert({message: LanguageModule.text("war_txt_system_lock")}); } else if (message == "deleted" || message == "edited"){ ModalElement.alert({ message: LanguageModule.text("war_txt_failed_ver_reload_data") }); } else if (message == "exist_name"){ ModalElement.alert({message: LanguageModule.text("war_txt_exist_name")}); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.editWork_flowClose = function(host, id, getValueFunction){ return new Promise(function(resolve, reject){ var data = getValueFunction("no_alert"); if (!data){ resolve(); return; } var oldData = host.dataWork_flowEdit; var ischange = contentModule.isChanged(oldData, data, ["name", "groupid", "description", "type_extra_of_object", "input_form_extra_of_object", "output_form_extra_of_object", "mobile_input_form_extra_of_object", "mobile_output_form_extra_of_object", "available"]); if (!ischange){ resolve(); return; } contentModule.questionChange({ onclick: function(sel){ if (sel == 0){ hr.work_flows.editWork_flowSubmit(host, host.id, getValueFunction).then(function(){ resolve(); }); } else if (sel == 1){ resolve(); } } }); }); }; hr.work_flows.redrawDetails = function(host, id){ var formContainer = DOMElement.div({}); var getValueFunction; contentModule.makeFormData({ typeid: host.form_config.work_flows.typeid, formid: host.form_config.work_flows.input_form, initialValue: host.dataWork_flowEdit, formContainer: formContainer, typelists: host.database.typelists.items, variableType: "system" }).then(function(getValue){ getValueFunction = getValue; formContainer.formFragment.setContext('host', host); absol.form.traversal(formContainer.formFragment.view, function(item){ if (item.node.tag === "TextInput") { item.node.domElt.focus(); item.stop(); return; } }); formContainer.formFragment.afterEntryCompleted().then(function(){ var elt = absol.form.findComponent(formContainer.formFragment.view, { name: 'type_work_flow_type_extra_of_object', depth: false }); if (elt && elt.attributes.value != 0){ elt.domElt.disabled = true; } }); }); theme.formWork_flowsEdit({ title: LanguageModule.text("txt_general_information"), frameList: host.frameList, formContainer: formContainer, func: { save: function(){ return hr.work_flows.editWork_flowSubmit(host, host.id, getValueFunction); }, cancel: function(){ return hr.work_flows.editWork_flowClose(host, host.id, getValueFunction); } } }); }; hr.work_flows.editWork_flow = function(host, id){ ModalElement.show_loading(); FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "work_flows_load_by_id"}, {name: "id", value: id} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ host.dataWork_flowEdit = EncodingClass.string.toVariable(message.substr(2)); var index = host.database.work_flows.getIndex(id); host.dataWork_flowEdit.marked = host.database.work_flows.items[index].marked; if (host.dataWork_flowEdit.extrainfo == "") host.dataWork_flowEdit.extrainfo = {}; else host.dataWork_flowEdit.extrainfo = EncodingClass.string.toVariable(host.dataWork_flowEdit.extrainfo); hr.work_flows.redrawDetails(host, id); } else if (message == "war_txt_failed_data"){ ModalElement.alert({ message: LanguageModule.text("war_txt_failed_data"), func: function(){ hr.work_flows.init(host); } }); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; hr.work_flows.addWork_flowSubmit = function(host){ return new Promise(function(resolve, reject){ var data = host.general_informationEdit.getValue(); data.extrainfo = EncodingClass.string.fromVariable(data.extrainfo); var dataPeriod = host.periodEdit.getValue(); var dataPermission = host.permissionEdit.getValue(); ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_save_new.php", params: [ {name: "data", value: EncodingClass.string.fromVariable(data)}, {name: "dataPeriod", value: EncodingClass.string.fromVariable(dataPeriod)}, {name: "dataPermission", value: EncodingClass.string.fromVariable(dataPermission)} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message. substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); st.privView = true; if (hr.isMobile) st.default_open = "table"; else st.default_open = "kanban"; host.database.work_flows.items.push(st); resolve(); hr.work_flows.redraw(host); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.addDatatypeSubmit = function(host){ return new Promise(function(resolve, reject){ function saveFunc(){ FormClass.api_call({ url: "datatypes_save.php", params: [{name: "data", value: EncodingClass.string.fromVariable(data)}], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ id = parseInt(message.substr(2)); data.tindex = 0; data.id = id; contentModule.makeTypelistsIndex(host); resolve(data); ModalElement.close(); } else if (message == "failed_ver" || message == "failed_id"){ ModalElement.alert({ message: LanguageModule.text("war_txt_failed_ver_reload_data") }); } else if (message == "war_txt_exist_name"){ ModalElement.alert({ message: LanguageModule.text("war_txt_exist_name"), func: function(){ host.formDatatypesEdit.name_inputtext.focus(); } }); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; var data = host.formDatatypesEdit.getValue(); if (!data) return; data.id = 0; data.lastmodifiedtime = new Date(); data.includedid = contentModule.getIncludedid(host, data.content.typeof) + "_"; data.ver = 1; data.userid = systemconfig.userid; data.createdtime = new Date(); for (var i = 0; i < host.database.typelists.items.length; i++){ if (host.database.typelists.items[i].name == data.name){ ModalElement.alert({ message: LanguageModule.text("war_txt_exist_name"), func: function(){ host.formDatatypesEdit.name_inputtext.focus(); } }); return; } } ModalElement.show_loading(); saveFunc(); }); }; hr.work_flows.addDatatype = function(host){ return new Promise(function(resolve, reject){ var listTypeOfExtends = []; var typeid; for (var i = 0; i < host.database.typelists.items.length; i++){ if (host.database.typelists.items[i].type == "objects"){ listTypeOfExtends.push({ value: host.database.typelists.items[i].id, text: host.database.typelists.items[i].name }); typeid = host.database.typelists.items[i].id; break; } } if (typeid == 0) return; var data = { name: "", type: "extends", content: { typeof: typeid, details: [] }, available: 1, extrainfo: { comment: "", decpre: 2 } }; data.listType = [{value: "extends", text: LanguageModule.text("txt_extends"), stt: 0, desc: LanguageModule.text("txt_system")}]; for (var i = 0; i < host.database.typelists.items.length; i++){ if (host.database.typelists.items[i].type == "extends_structure" && host.database.typelists.items[i].includedid && host.database.typelists.items[i].includedid.indexOf("_" + typeid + "_") >= 0){ listTypeOfExtends.push({ value: host.database.typelists.items[i].id, text: host.database.typelists.items[i].name }); } } data.listTypeOfExtends = listTypeOfExtends; data.listTypeOfStructure = []; data.listTypeOfUnion = []; host.database.typelists.items.forEach(function(item){ if (!item.available) return; if (item.id < 0) desc = LanguageModule.text("txt_system"); else desc = LanguageModule.text("txt_user"); data.listTypeOfStructure.push({value: item.id, text: item.name, stt: item.stt, desc: desc}); if ((item.type == "enum" || item.type2 == "enum") && !item.notTypeOfUnion){ data.listTypeOfUnion.push({value: item.id, text: item.name, stt: item.stt, desc: desc}); } }); data.listTypeOfStructure.push({value: "union", text: LanguageModule.text("txt_union"), desc: LanguageModule.text("txt_system")}); host.formDatatypesEdit = theme.formDatatypesEdit({ data: data, database: host.database, type: "add" }); ModalElement.showWindow({ title: LanguageModule.text("txt_add_data_type"), bodycontent: host.formDatatypesEdit, buttonlist: [ { text: LanguageModule.text("txt_save"), onclick: function(){ hr.work_flows.addDatatypeSubmit(host).then(function(value){ resolve(value); }); } }, { text: LanguageModule.text("txt_cancel"), onclick: function(){ ModalElement.close(); } } ] }); }); }; hr.work_flows.getInforNewCtn = function(host){ var formContainer = DOMElement.div({}); contentModule.makeFormData({ typeid: host.form_config.work_flows.typeid, formid: host.form_config.work_flows.input_form, formContainer: formContainer, typelists: host.database.typelists.items, variableType: "system" }).then(function(getValue){ formContainer.getValue = getValue; formContainer.formFragment.setContext('host', host); absol.form.traversal(formContainer.formFragment.view, function(item){ if (item.node.tag === "TextInput") { item.node.domElt.focus(); item.stop(); return; } }); formContainer.formFragment.afterEntryCompleted().then(function(){ var elt = absol.form.findComponent(formContainer.formFragment.view, { name: 'type_work_flow_member_of_typelists', depth: false }); if (elt){ var x = elt.domElt.items; x.splice(1, 0, {value: -1, text: LanguageModule.text("txt_add_data_type_select")}); elt.domElt.items = x; elt.domElt.on("change", function(){ if (this.value == -1){ hr.work_flows.addDatatype(host).then(function(value){ host.database.typelists.items.push(value); x.push({value: value.id, text: value.name}); elt.attributes.items = x; elt.attributes.value = value.id; }); } }); } }); }); return formContainer; }; hr.work_flows.getEditPeriodCtn = function(host, id){ var list = []; if (id > 0){ list = list.concat(host.dataPeriod); } var listSystem = contentModule.getObjectPeriodSystemList(); list = list.concat(listSystem); return theme.formWork_flowsGetPeriodEdit({ list: list, systemlength: listSystem.length }); }; hr.work_flows.getPermissionCtn = function(host, id){ delete host.employeeEditDic; delete host.orgViewDic; delete host.orgEditDic; var employeeItems = contentModule.getOrgsAndEmployeesListSelectTreeMenu(host); employeeItems.splice(0, 1); var x = absol.buildDom({ tag: "multichecktreemenu", style: { verticalAlign: "middle" }, props: { items: employeeItems, enableSearch: true } }); if (id > 0) x.values = host.dataMember; employeeItems = contentModule.getOrgsAndEmployeesListSelectTreeMenuLeaf(host); var y = absol.buildDom({ tag: "multichecktreeleafmenu", style: { verticalAlign: "middle" }, props: { items: employeeItems, enableSearch: true } }); if (id > 0) y.values = host.dataAdminPrivileges; var res = DOMElement.div({ children: [ DOMElement.div({ attrs: { style: { lineHeight: "var(--control-height)", fontWeight: "bold" } }, text: LanguageModule.text("txt_which_employees_are_authorized_to_use_this_work_flow") }), DOMElement.div({ children: [ DOMElement.span({ attrs: { style: { lineHeight: "var(--control-height)", verticalAlign: "middle", marginRight: "var(--control-horizontal-distance-2)" } }, text: LanguageModule.text("txt_employee") }), x ] }), DOMElement.div({ attrs: { style: { lineHeight: "var(--control-height)", fontWeight: "bold" } }, text: LanguageModule.text("txt_which_employees_are_authorized_to_use_and_edit_all_object_this_work_flow") }), DOMElement.div({ children: [ DOMElement.span({ attrs: { style: { lineHeight: "var(--control-height)", verticalAlign: "middle", marginRight: "var(--control-horizontal-distance-2)" } }, text: LanguageModule.text("txt_employee") }), y ] }) ] }); res.getValue = function(){ return { members: x.values, admin_privileges: y.values }; }; return res; }; hr.work_flows.getPermissionViewCtn = function(host, id){ delete host.employeeEditDic; delete host.orgViewDic; delete host.orgEditDic; var employeeItems = contentModule.getOrgsAndEmployeesListSelectTreeMenu(host); var employeeItemsDic = new absol.ListDictionary(employeeItems); var x = "", item; for (var i = 0; i < host.dataMember.length; i++){ item = employeeItemsDic.getItemByValue(host.dataMember[i]); if (item) x += "; " + item.text; } if (x.length > 0) x = x.substr(2); employeeItems = contentModule.getOrgsAndEmployeesListSelectTreeMenuLeaf(host); employeeItemsDic = new absol.ListDictionary(employeeItems); var y = "", item; for (var i = 0; i < host.dataAdminPrivileges.length; i++){ item = employeeItemsDic.getItemByValue(host.dataAdminPrivileges[i]); if (item) y += "; " + item.text; } if (y.length > 0) y = y.substr(2); var res = DOMElement.div({ children: [ DOMElement.div({ attrs: { style: { lineHeight: "var(--control-height)", fontWeight: "bold" } }, text: LanguageModule.text("txt_which_employees_are_authorized_to_use_this_work_flow") }), DOMElement.div({ children: [ DOMElement.span({ attrs: { style: { lineHeight: "var(--control-height)", marginRight: "var(--control-horizontal-distance-2)" } }, text: LanguageModule.text("txt_employee") + ": " + x }) ] }), DOMElement.div({ attrs: { style: { lineHeight: "var(--control-height)", fontWeight: "bold" } }, text: LanguageModule.text("txt_which_employees_are_authorized_to_use_and_edit_all_object_this_work_flow") }), DOMElement.div({ children: [ DOMElement.span({ attrs: { style: { lineHeight: "var(--control-height)", marginRight: "var(--control-horizontal-distance-2)" } }, text: LanguageModule.text("txt_employee") + ": " + y }) ] }) ] }); return res; }; hr.work_flows.addWork_flow = function(host){ var redraw = function(){ host.general_informationEdit = hr.work_flows.getInforNewCtn(host); host.periodEdit = hr.work_flows.getEditPeriodCtn(host, 0); host.permissionEdit = hr.work_flows.getPermissionCtn(host, 0, "edit"); theme.formWork_flowsAdd({ general_informationEdit: host.general_informationEdit, periodEdit: host.periodEdit, permissionEdit: host.permissionEdit, frameList: host.frameList, func: { save: function(){ return hr.work_flows.addWork_flowSubmit(host); } } }); }; if (host.orgsLoaded){ redraw(); } else { ModalElement.show_loading(); data_module.loadEmployeeItemsPrivView().then(function(values){ for (x in values.database){ host.database[x] = values.database[x]; } ModalElement.close(-1); host.orgsLoaded = true; redraw(); }); } }; hr.work_flows.editPeriodSubmit = function(host, id, data){ return new Promise(function(resolve, reject){ FormClass.api_call({ url: "work_flows_save_periods.php", params: [ {name: "id", value: id}, {name: "data", value: EncodingClass.string.fromVariable(data)} ], func: function(success, message){ if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); resolve(st); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.editPeriod = function(host, id){ var res = hr.work_flows.getEditPeriodCtn(host, id); theme.formWork_flowsEditPeriods({ title: LanguageModule.text("txt_period"), data_ctn: res, frameList: host.frameList, func: { save: function(){ return new Promise(function(resolve, reject){ var x = res.getValue(); if (!x) return; var data = { updateList: [], insertList: [], deleteList: [] }; var dict = {}; for (var i = 0; i < x.length; i++){ if (x[i].id == 0){ data.insertList.push({ name: x[i].name, color: x[i].color, work_flowid: id, stt: i }); } else { dict[x[i].id] = { id: x[i].id, name: x[i].name, color: x[i].color, stt: i }; } } for (var i = 0; i < host.dataPeriod.length; i++){ if (dict[host.dataPeriod[i].id]){ data.updateList.push(dict[host.dataPeriod[i].id]); } else { data.deleteList.push(host.dataPeriod[i].id); } } ModalElement.show_loading(); hr.work_flows.editPeriodSubmit(host, id, data).then(function(st){ ModalElement.close(-1); resolve(); if (st.listUndelete.length > 0){ var getIndex = function(id){ for (var i = 0; i < host.dataPeriod.length; i++){ if (host.dataPeriod[i].id == id) return i; } } if (st.listUndelete.length == 1){ var index = getIndex(st.listUndelete[0].id); var periodName = host.dataPeriod[index].name; ModalElement.alert({message: "Không thể xóa giai đoạn '" + periodName + "' vì đang có đối tượng"}); } else { var periodNameList = "", index; for (var i = 0; i < st.listUndelete.length; i++){ index = getIndex(st.listUndelete[i].id); periodNameList += ", " + host.dataPeriod[index].name; } periodNameList = periodNameList.substr(2); ModalElement.alert({message: "Không thể xóa các giai đoạn '" + periodNameList + "' vì đang có đối tượng"}); } } host.dataPeriod = st.work_flow_periods; host.drawPeriodsFunc(); }); }); } } }); }; hr.work_flows.editPermissionSubmit = function(host, id, data){ return new Promise(function(resolve, reject){ ModalElement.show_loading(); FormClass.api_call({ url: "work_flows_save_members.php", params: [ {name: "id", value: id}, {name: "dataPermission", value: EncodingClass.string.fromVariable(data)} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ host.dataMember = data.members; host.dataAdminPrivileges = data.admin_privileges; host.drawPermissionsFunc(); resolve(); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.work_flows.editPermission = function(host, id){ var res = hr.work_flows.getPermissionCtn(host, id, "edit"); theme.formWork_flowsEditPermission({ title: LanguageModule.text("txt_permission"), frameList: host.frameList, data_ctn: res, func: { save: function(){ var data = res.getValue(); return hr.work_flows.editPermissionSubmit(host, id, data); } } }); }; hr.work_flows.settingWork_flow = function(host, id){// TODO: host.id = id; host.drawGeneralInforFunc = function(viewGeneralInformation){ if (!viewGeneralInformation) viewGeneralInformation = host.viewGeneralInformation; else host.viewGeneralInformation = viewGeneralInformation; contentModule.makeOutputFormData({ typeid: host.form_config.work_flows.typeid, formid: host.form_config.work_flows.output_form, initialValue: host.dataWork_flowEdit, formContainer: viewGeneralInformation, typelists: host.database.typelists.items, variableType: "system" }).then(function(getValue){ viewGeneralInformation.formFragment.setContext('host', host); }); }; host.drawPeriodsFunc = function(viewPeriod){ if (viewPeriod) host.viewPeriod = viewPeriod; else viewPeriod = host.viewPeriod; var list = []; for (var i = 0; i < host.dataPeriod.length; i++){ list.push(host.dataPeriod[i]); } var listSystem = contentModule.getObjectPeriodSystemList(); for (var i = 0; i < listSystem.length; i++){ list.push(listSystem[i]); } var tableView = theme.formWork_flowsViewPeriods({ list: list }); DOMElement.removeAllChildren(viewPeriod); viewPeriod.appendChild(DOMElement.div({ attrs: {className: "cardsimpletableclass"}, children: [tableView] })); }; host.drawPermissionsFunc = function(viewPermission){ if (viewPermission) host.viewPermission = viewPermission; else viewPermission = host.viewPermission; DOMElement.removeAllChildren(viewPermission); var x = hr.work_flows.getPermissionViewCtn(host, host.id); viewPermission.appendChild(x); }; theme.formSettingWorkFlow(host, { func: { edit_general_information_func: function(){ hr.work_flows.editWork_flow(host, host.id); }, edit_periods_func: function(){ hr.work_flows.editPeriod(host, host.id); }, edit_permission_func: function(){ hr.work_flows.editPermission(host, host.id); } } }); }; hr.work_flows.settingWork_flowPre = function(host, id){ var loadData = function(){ FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "work_flows_load_all_info_by_id"}, {name: "id", value: id} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == 'ok'){ var st = EncodingClass.string.toVariable(message.substr(2)); host.dataWork_flowEdit = st.data; if (host.dataWork_flowEdit.extrainfo == "") host.dataWork_flowEdit.extrainfo = {}; else host.dataWork_flowEdit.extrainfo = EncodingClass.string.toVariable(host.dataWork_flowEdit.extrainfo); host.dataPeriod = st.dataPeriod; host.dataMember = []; for (var i = 0; i < st.dataMember.length; i++){ host.dataMember.push(st.dataMember[i].orgid); } host.dataAdminPrivileges = []; for (var i = 0; i < st.dataAdminPrivileges.length; i++){ host.dataAdminPrivileges.push(st.dataAdminPrivileges[i].employeeid); } hr.work_flows.settingWork_flow(host, id); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; ModalElement.show_loading(); if (host.orgsLoaded){ loadData(); } else { ModalElement.show_loading(); data_module.loadEmployeeItemsPrivView().then(function(values){ for (x in values.database){ host.database[x] = values.database[x]; } host.orgsLoaded = true; loadData(); }); } }; hr.work_flows.getCellWork_flow = function(host, id){ var index = host.database.work_flows.getIndex(id); var func = {}; if (systemconfig.privSystem >= 2 || data_module.admin_rights_of_me.work_flows) func.setting = function(){ hr.work_flows.settingWork_flowPre(host, id); }; func.view = function(){ hr.work_flows.showWorkFlow(host, id, "kanban"); }; func.table_view = function(){ hr.work_flows.showWorkFlow(host, id, "table"); }; if (systemconfig.privSystem >= 2 || data_module.admin_rights_of_me.work_flows) func.delete = function(){ return new Promise(function(resolve, reject){ hr.work_flows.deleteWork_flowConfirm(host, id).then(function(value){ resolve(value); }); }); }; func.markedFunc = function(marked){ return contentModule.markedFunc(host, { id: id, marked: marked, task: "work_flows", tablename: "work_flows" }); }; var res = host.database.work_flows.items[index]; res.func = func; return res; }; hr.work_flows.redraw = function(host){ console.log(new Date().getTime(), 5); var groupid = host.group_select.value; theme.formWork_flowsContentData({ database: host.database, inputsearchbox: host.inputsearchbox, ctn: host.data_container, form_config: host.form_config, user_column_configsDic: host.user_column_configsDic, groupid: groupid, getCellWork_flow: function(id){ return hr.work_flows.getCellWork_flow(host, id); } }); }; hr.work_flows.init = function(host){ return new Promise(function(resolveMn, rejectMn){ hr.menu.changeCurrentUrlTab(host, "work_flows"); host.database = {}; var loadPriv = 1; if (systemconfig.privSystem >= 2 || data_module.admin_rights_of_me.work_flows) loadPriv = 0; if (data_module.employeeOfMe.length == 0) loadPriv = 0; ModalElement.show_loading(); FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "work_flows_load_init"}, {name: "loadPriv", value: loadPriv} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var content = EncodingClass.string.toVariable(message.substr(2)); host.employeeOfMe = content.employeeOfMe; delete content.employeeOfMe; contentModule.makeDatabaseContent(host, content); contentModule.makeTypelistsIndex(host); host.form_config = contentModule.configVariable(host); host.user_column_configsDic = contentModule.getUser_column_configsDic(host); contentModule.makePrivilegeViewWorkFlow(host); contentModule.makeUserMarkerData(host, "work_flows"); contentModule.makeUser_workflow_type_viewsDefault(host); var cmdbutton = { close: function (event, me) { if (hr.isMobile){ hr.menu.loadPage(1000); } else { hr.menu.tabPanel.removeTab(host.holder.id); } } }; if (systemconfig.privSystem >= 2 || data_module.admin_rights_of_me.work_flows) cmdbutton.add = function(event, me) { hr.work_flows.addWork_flow(host); }; host.data_container = DOMElement.div({}); host.holder.addChild(host.frameList); var singlePage = theme.formWork_flowsInit({ database: host.database, cmdbutton: cmdbutton, data_container: host.data_container, filter_change_func: function(){ hr.work_flows.redraw(host); } }); host.inputsearchbox = singlePage.inputsearchbox; host.group_select = singlePage.group_select; host.frameList.addChild(singlePage); singlePage.requestActive(); hr.work_flows.redraw(host); resolveMn(host); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); };