define(function(require, exports, module) { var Window = require('system/views/pages/window'); var tpl = require('text!apps/edp/frs/frs004/QuickSetEtp.tpl'); require('css!./QuickSetEtp.css'); //var MSG = require('../../../../locale/{lang}/ssm_frs'); // _.extend(Store.MSG, MSG); var _UiObjCode = ''; var _index = 0; //用于记录搜索行的index var _textBoxCaption; //用于记录上次进行搜索的文本 /** * [快速设置弹框] * @param {[type]} dsRole 角色表数据源,用于对角色ComBox进行赋值 */ function QuickSetEtp(UiObjCode, callback) { this.options = { title: Store.MSG.FRS004_10, //快速设置 content: tpl, width: 812, height: 620, modal: true, closed: true, closable: true, draggable: false, data: null } this.UiObjCode = UiObjCode; _UiObjCode = UiObjCode; this.callback = callback; Window.call(this, this.options); } inherits(QuickSetEtp, Window); QuickSetEtp.prototype.init = function() { var self = this; var mainGrid = { opts: { editable: true, enableAddRow: false, pageSize: 50 }, data: self.vFrsQuickSetRef, actions: {} } var mainToolBar = { opts: {}, data: [{ opCode: 'ok', caption: Store.MSG.FRS004_06, //确认 hint: Store.MSG.FRS004_06, //确认 parentOp: '', opClass: 'ok' }, { opCode: 'sort', caption: Store.MSG.FRS004_07, //排序 hint: Store.MSG.FRS004_07, parentOp: '', opClass: 'list' }, { opCode: 'refresh', caption: Store.MSG.FRS004_11, //刷新 hint: Store.MSG.FRS004_11, parentOp: '', opClass: 'refresh' }, { opCode: 'exit', caption: Store.MSG.FRS004_09, //退出 hint: Store.MSG.FRS004_09, parentOp: '', opClass: 'cancel' }], actions: { click: function(opCode) { self.doOp(opCode); } } } this.register('grid', 'grid_main', mainGrid); this.register('toolbar', 'toolbar_main', mainToolBar); } QuickSetEtp.prototype.doOp = function(opCode) { switch (opCode) { case 'refresh': this.refresh(); break; case 'ok': this.sure(); break; case 'sort': this.sort(); break; case 'exit': this.close(); break; } }; /** * 刷新事件 * @return {[type]} [description] */ QuickSetEtp.prototype.refresh = function() { var self = this; Store.messager.confirm(Store.MSG.FRS004_13, function(r) { if (r) { self.vFrsQuickSetRef.clear(); self.getDataSets(self); } }); }; /** * 确定事件 * @return {[type]} [description] */ QuickSetEtp.prototype.sure = function() { var self = this; var allow = this.vFrsQuickSetRef.onBeforeDataSrcSave(); if (!allow) { return; } //点击确定时,先进行排序,在将序号按照目前的顺序进行重新排序,防止出现重复序号或者间隔的序号 this.sort(); var rowDispIndex = 0; var quickSetRows = this.vFrsQuickSetRef.rows; _.each(quickSetRows, function(item, index) { item.setColumnValue('DispIndex', rowDispIndex); rowDispIndex++; }); //将修改的数据插入到对应表中 var changedRows = this.vFrsQuickSetRef.getChanges(); var changeData = new Array(); changedRows.forEach(function(e) { changeData.push(e.getData()); }); //save var params = { plugin: 'quickSetEtpSavePlugin', pluginData: { changedrows: changeData, uiobjcode: _UiObjCode, } }; Store.services.executeplugin(params, function(isOk, result) { if (isOk) { Store.messager.tip(Store.MSG.FRS004_25); //保存成功。 if (self.callback) { self.callback(); } }; }); this.close(); }; /** * 排序事件 * @return {[type]} [description] */ QuickSetEtp.prototype.sort = function() { var self = this; var rows = this.vFrsQuickSetRef.rows; //提交编辑焦点 if (!self.widgets.grid_main.commitEditor()) { return; } if (rows == null) return; for (var i = rows.length; i > 0; i--) { for (var j = 0; j < i - 1; j++) { if (parseInt(rows[j]["DispIndex"]) > parseInt(rows[j + 1]["DispIndex"])) { var row = rows[j]; self.vFrsQuickSetRef.rows[j] = rows[j + 1]; self.vFrsQuickSetRef.rows[j + 1] = row; } } } //重置界面数据 self.widgets.grid_main.setData(self.vFrsQuickSetRef.rows); }; //对视图灌入数据 QuickSetEtp.prototype.getDataSets = function(win) { var self = win; var params = { plugin: 'quickSetEtpFrushPlugin', pluginData: { uiobjcode: _UiObjCode, } }; Store.services.executeplugin(params, function(isOk, result) { if (isOk) { self.vFrsQuickSetRef.loadData(result.data); if (self.callback) { self.callback(); } }; }); } QuickSetEtp.prototype.open = function() { var self = this; var code = "vFrsQuickSetRef;tEtpUIProp01"; var post_data = { funcCode: '', uiObjCodes: code } //获取所有的需要数据 Store.services.getUiObjSchema(post_data, function(isOk, data) { if (isOk) { var codes = code.split(';'); for (var c in codes) { self[codes[c]] = new DataSource({ funcObjCode: codes[c] }); self[codes[c]].initUIObj(data[codes[c]]); if (0 < _.where(self[codes[c]].columns, { 'fieldName': 'UIObjCode' }).length) { self[codes[c]].fixQuery = { UIObjCode: _UiObjCode }; } //设置快速设置界面不允许增加新行 self.vFrsQuickSetRef.allowInsert = false; } self.getDataSets(self); Window.prototype.open.call(self); } }); } //执行windows窗体上自定义按钮事件 QuickSetEtp.prototype.customerize = function() { var self = this; //首先刷新,否则分页记录条数不正确 // this.vFrsQuickSetRef.fixQuery['UIObjCode'] = _UiObjCode; // this.vFrsQuickSetRef.search(); this.vFrsQuickSetRef.on('onDataColumnValidate', function(ds, args) { var column = args.col; if (column.fieldName == "DispIndex") { var count = 0; //判断当前序号存在多少个 var quickFlag = false; var fieldName = args.row.FieldName; var newDispIndex = parseInt(args.value); var oldDispIndex = parseInt(args.row._origin.DispIndex); //用于标记目前是否存在该序号,如果存在进行操作,如果不存在则不修改其他序号 var quickSetDr = self.vFrsQuickSetRef; var quickSetRows = quickSetDr.rows; _.each(quickSetRows, function(item, index) { var rowFieldName = item["FieldName"]; var rowDispIndex = item["DispIndex"]; if (rowFieldName != fieldName && rowDispIndex == newDispIndex) { quickFlag = true; } if (rowFieldName != fieldName && rowDispIndex == oldDispIndex) { count++; } }); if (!quickFlag) return; //存在重复序号时的处理逻辑 if (count > 0) { var dispIndex = newDispIndex; _.each(quickSetRows, function(item, index) { var rowFieldName = item["FieldName"]; var rowDispIndex = item["DispIndex"]; if (rowFieldName != fieldName && rowDispIndex >= newDispIndex) { dispIndex++; item.setColumnValue('DispIndex', dispIndex); } }); } else { if (oldDispIndex < newDispIndex) { _.each(quickSetRows, function(item, index) { var rowFieldName = item["FieldName"]; var rowDispIndex = item["DispIndex"]; if (rowFieldName != fieldName && rowDispIndex > oldDispIndex && rowDispIndex <= newDispIndex) { rowDispIndex--; item.setColumnValue('DispIndex', rowDispIndex); } }); } if (oldDispIndex > newDispIndex) { _.each(quickSetRows, function(item, index) { var rowFieldName = item["FieldName"]; var rowDispIndex = item["DispIndex"]; if (rowFieldName != fieldName && rowDispIndex >= newDispIndex && rowDispIndex < oldDispIndex) { rowDispIndex++; item.setColumnValue('DispIndex', rowDispIndex); } }); } } } if (column.fieldName == "DefaultValue") { //if (args.row._origin.DefaultValue == null) { // Store.messager.tip(Store.MSG.FRS004_17); //初始默认值为空时,不允许设置默认值。 // args.isCancel = true; //} if (args.row._origin.DefaultValue != null && args.value == "") { Store.messager.tip(Store.MSG.FRS004_16); //默认值不允许修改为空,请重新输入。 args.isCancel = true; } } if (column.fieldName == "IsRequired") { if (args.row._origin.IsRequired == "1" && args.value == "0") { Store.messager.tip(Store.MSG.FRS004_18); //初始值为必填时,不允许修改为不必填。 args.row.setColumnValue('IsRequired', "1"); args.isCancel = true; } } }); //搜索按钮事件 var textSearch = this.getElement('.searchDispName'); textSearch.textbox('textbox').bind('keydown', function(e) { if (e.keyCode == 13) { // when press ENTER key, accept the inputed value. search(textSearch, self); textSearch.focus(); } }); var btnSearch = this.getElement('.btnSearchDispName'); btnSearch.on('click', function(event) { search(textSearch, self); }); } /** * 搜索方法 * @param {[type]} textSearch [输入框] * @param {[type]} self [弹框自身] * @return {[type]} [description] */ function search(textSearch, self) { var textBoxCaption = textSearch.val(); var curRow = self.vFrsQuickSetRef.currentRow; var flag = 0; //标记是否找到匹配项,如果未找到,系统给出提示:“未找到任何显示标题包含({0})关键字,请重新输入”。 if (curRow != "") { if (textBoxCaption !== "") { if (_textBoxCaption != textBoxCaption) { _index = 0; } var rows = self.vFrsQuickSetRef.rows; if (rows === "") return; for (var i = _index + 1; i < rows.length; i++) { var dispName = rows[i]["DispName"]; if (dispName.indexOf(textBoxCaption) >= 0) { self.vFrsQuickSetRef.moveTo(i); _textBoxCaption = textBoxCaption; _index = i; flag = 1; return; } } for (var i = 0; i <= _index; i++) { var dispName = rows[i]["DispName"]; if (dispName.indexOf(textBoxCaption) >= 0) { self.vFrsQuickSetRef.moveTo(i); _textBoxCaption = textBoxCaption; _index = i; flag = 1; return; } } if (flag == 0) { textSearch.textbox('setValue', '') Store.messager.tip(Store.format(Store.MSG.FRS004_15, textBoxCaption)); //没有找到包含({0})关键字的显示标题。 textSearch.focus(); return; } } else { self.vFrsQuickSetRef.moveTo(0); } } } /** * 获取本业务的层列明细表数据 * @param {[type]} code [数据源] * @param {[type]} data [数据] * @param {[type]} self [description] * @param {Function} callback [description] */ return QuickSetEtp; })