define(function (require, exports, module) { var Window = require('system/views/pages/window'); var tpl = require('text!apps/edp/frd/frd002/refwin.tpl'); // var DataSource = require('system/base/datasource'); function PropRef(args) { this.options = { title: '属性参照', content: tpl, width: 612, height: 435, modal: true, closed: true, closable: true, data: null } this.args = args; Window.call(this, this.options); this.dsDetail = new DataSource({ funcObjCode: 'tFrmUIProp' }); } inherits(PropRef, Window); PropRef.prototype.init = function () { var self = this; var tree = { data: this.args.data, actions: { onClick: function (event, treeNode) { var uiObjCode = treeNode.uiObjCode; if (uiObjCode !== undefined) { self.dsDetail.fixQuery = { UIObjCode: uiObjCode }; self.dsDetail.search(function (isOk) { if (isOk) { var items = parseFieldItems(self.dsDetail); self.$cmbField.combobox('loadData', items); self.$cmbField.combobox('clear'); self.$cmbFieldName.combobox('loadData', items); self.$cmbFieldName.combobox('clear'); } }); } } } } this.register('tree', 'tree_obj', tree); } PropRef.prototype.open = function () { var self = this; var code = this.dsDetail.uiObjCode; var post_data = { funcCode: '', uiObjCodes: code }; Store.services.getUiObjSchema(post_data, function (isOk, data) { if (isOk) { self.dsDetail.initUIObj(data[self.dsDetail.uiObjCode]); Window.prototype.open.call(self); } }); }; PropRef.prototype.customerize = function ($container) { var self = this; this.$cmbField = this.getElement('.cmbField'); this.$cmbFieldName = this.getElement('.cmbFieldName'); var $btnOk = this.getElement('.btnOk'); if ($btnOk) { $btnOk.on('click', function () { self.doOp('ok'); }); } var $btnCancel = this.getElement('.btnCancel'); if ($btnCancel) { $btnCancel.click(function () { self.doOp('exit'); }); } var nodes = parseTreeData(self.args.dataSrc); self.vm.tree_obj.reset(nodes); // self.dsDetail.search(function (isOk) { // if (isOk) { // var items = parseFieldItems(self.dsDetail); // self.$cmbField.combobox('loadData', items); // self.$cmbField.combobox('clear'); // self.$cmbFieldName.combobox('loadData', items); // self.$cmbFieldName.combobox('clear'); // } // }); }; /** * 转化ds数据为字段元素 * {text:[fieldName],value:[rowindex]} * @param {Object} ds 数据源 * @return {Array} 字段数组 */ function parseFieldItems(ds) { var items = []; for (var i = 0; i < ds.rows.length; i++) { var row = ds.rows[i]; var item = { text: row['DispName'], value: row['FieldName'] } items.push(item); } ; return items; } /** * 转为ds数据为树节点数据 * {row:[rowindex],id:[UIObjCode],pId:[ModuleCode],name:[UIObjName]} * @param {Object} ds 数据源 * @return {Array} 树数据 */ function parseTreeData(ds) { var nodes = []; // var root = { // pId: '', // id: '*', // name: '表参照字段' // }; // nodes.push(root); for (var i = 0; i < ds.rows.length; i++) { var row = ds.rows[i]; if (row['RefType'] == Store.Enums.RefType.TABLE) { var treeNode = { uiObjCode: row['RefObj'], pId: '*', id: row['FieldName'], name: row['DispName'] || row['FieldName'] }; nodes.push(treeNode); } } ; return nodes; } PropRef.prototype.select = function () { var refObj = this.vm.tree_obj.getSelected().id; if (!refObj) { Store.showError(Store.MSG.UIOBJ_NOT_SELECT); return; } var refField = this.$cmbField.combobox('getValue'); var refFieldName = this.$cmbFieldName.combobox('getValue'); if (this.args.row) { this.args.row.validator('RefObj', refObj); this.args.row.validator('RefField', refField); this.args.row.validator('RefFieldName', refFieldName); } if (this.args.callback) { this.args.callback(refObj); } this.close(); }; PropRef.prototype.doOp = function (opCode) { var isHandled = false; switch (opCode) { case 'ok': this.select(); break; case 'exit': this.close(); break; case 'refresh': this.refresh(); } }; PropRef.prototype.refresh = function () { var self = this; //表参照专用,表参照相关约束 this.args.refParam.ignoreValue = true; this.dsMaster.refQuery = this.args.refParam; this.dsMaster.search(); }; return PropRef; })