You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

284 lines
9.9 KiB

define(function (require, exports, module) {
var BaseWindow = require('system/views/pages/window');
require('css!./scriptwin2.css');
var tpl = require('text!./scriptwin2.tpl');
var insertScript = ['pFdp.']
function Window(args) {
this.options = {
title: args.dbType + '脚本查看器',
content: tpl,
width: 800,
height: 600,
modal: true,
closed: true,
closable: true,
data: null
}
this.args = args;
BaseWindow.call(this, this.options);
this.dsMaster = new DataSource();
this.dsMaster.uiObjCode = 'tFrmUIProp';
this.dsMaster.fixQuery['UIObjCode'] = args.dataRow['UIObjCode'];
}
inherits(Window, BaseWindow);
Window.prototype.init = function () {
var self = this;
}
Window.prototype.ok = function () {
this.close();
};
Window.prototype.doOp = function (opCode) {
var isHandled = false;
switch (opCode) {
case 'ok':
this.ok();
break;
case 'selectall':
this.$txtScript.select();
break;
case 'export':
this.exportScript();
break;
}
};
Window.prototype.customerize = function ($container) {
var self = this;
this.$txtScript = this.getElement('.txtscript');
this.$scriptNameInput = this.getElement('.edp-frd-script-name-input');
var $btnOk = this.getElement('.btn-script-ok');
if ($btnOk) {
$btnOk.on('click', function () {
self.doOp('ok');
});
}
var $btnCancel = this.getElement('.btn-script-cancel');
if ($btnCancel) {
$btnCancel.click(function () {
self.doOp('selectall');
});
}
var $btnExport = this.getElement('.btn-script-export');
if ($btnExport) {
$btnExport.click(function() {
self.doOp('export');
});
}
this.$scriptNameInput.val(this.scriptName);
self.loadScript();
};
Window.prototype.open = function () {
var self = this;
var code = self.dsMaster.uiObjCode;
var post_data = {
funcCode: '',
uiObjCodes: code
}
this.makeScriptName();
Store.services.getUiObjSchema(post_data, function (isOk, data) {
if (isOk) {
self.dsMaster.initUIObj(data[code]);
BaseWindow.prototype.open.call(self);
}
});
};
Window.prototype.exportScript = function() {
var self = this,
scriptContent = self.$txtScript.val(),
scriptName = self.$scriptNameInput.val(),
blob = new Blob(
[scriptContent],
{type: "text/plain;charset=" + document.characterSet}
),
url = window.URL.createObjectURL(blob),
download_link = $('.export-script')[0];
Store.services.fileExport({
filename: scriptName,
content: scriptContent
}, function (isok, data) {
if (isok) {
download_link.href = Store.host + data.path;
download_link.download = scriptName;
download_link.click();
window.URL.revokeObjectURL(url);
}
})
};
Window.prototype.loadScript = function () {
var self = this;
self.dsMaster.search(function (isOk, ds) {
if (isOk) {
self.createDictScript()
}
});
};
function getSpace(num) {
var str = '';
for (var i = 0; i < num; i++) {
str += ' ';
}
;
return str;
}
Window.prototype.makeScriptName = function() {
this.scriptName = Store.dbScriptsProjectNo + '06_' + this.args.dataRow['ModuleCode'] +
'_预置界面字典' + this.args.dataRow['UIObjCode'] + '.sql';
};
Window.prototype.createDictScript = function () {
var self = this;
var dbType = self.args.dbType;
var dictScriptTpl = require('text!./dictScript2.tpl');
if (dbType === 'mysql') {
dictScriptTpl = require('text!./dictScript2MySql.tpl');
}
//主表相关脚本
var objRow = self.args.dataRow;
var sqlObj = ["pFdp.sFrmUIObjScript("];
if (dbType ==='mysql') {
sqlObj = ["call sFrmUIObjScript("];
}
appendStr(sqlObj, getStrSql('UIObjCode', objRow, dbType));
appendStr(sqlObj, getStrSql('UIObjName', objRow, dbType));
appendStr(sqlObj, getStrSql('DataObjCode', objRow, dbType));
appendStr(sqlObj, getStrSql('DefaultOrder', objRow, dbType));
appendStr(sqlObj, getStrSql('MultiType', objRow, dbType));
appendStr(sqlObj, getStrSql('MultiFields', objRow, dbType));
appendStr(sqlObj, getStrSql('MultiMsg', objRow, dbType));
appendStr(sqlObj, getStrSql('TreeField', objRow, dbType));
appendStr(sqlObj, getStrSql('Headers', objRow, dbType));
appendStr(sqlObj, getStrSql('ModuleCode', objRow, dbType), true);
sqlObj += ");";
//明细脚本
var sqlProps = "";
for (var i = 0; i < self.dsMaster.rows.length; i++) {
var row = self.dsMaster.rows[i];
var sqlProp = ["pFdp.sFrmUIPropScript("];
if (dbType === 'mysql') {
sqlProp = ["call sFrmUIPropScript("];
}
appendStr(sqlProp, getStrSql('UIObjCode', row, dbType));
appendStr(sqlProp, getStrSql('FieldName', row, dbType));
appendStr(sqlProp, getNumSql('DispIndex', row, dbType));
appendStr(sqlProp, getStrSql('DispName', row, dbType));
appendStr(sqlProp, getNumSql('DispWidth', row, dbType));
appendStr(sqlProp, getNumSql('LabelWidth', row, dbType));
appendStr(sqlProp, getNumSql('HeaderWidth', row, dbType));
appendStr(sqlProp, getNumSql('DispScale', row, dbType));
appendStr(sqlProp, getStrSql('EditStyle', row, dbType));
appendStr(sqlProp, getStrSql('DispPosition', row, dbType));
appendStr(sqlProp, getStrSql('DefaultValue', row, dbType));
appendStr(sqlProp, getStrSql('DispFormat', row, dbType));
appendStr(sqlProp, getStrSql('IsFixed', row, dbType));
appendStr(sqlProp, getNumSql('PageId', row, dbType));
appendStr(sqlProp, getStrSql('Hint', row, dbType));
appendStr(sqlProp, getStrSql('IsStrictRef', row, dbType));
appendStr(sqlProp, getStrSql('Match', row, dbType));
appendStr(sqlProp, getStrSql('RefType', row, dbType));
appendStr(sqlProp, getStrSql('RefObj', row, dbType));
appendStr(sqlProp, getStrSql('RefField', row, dbType));
appendStr(sqlProp, getStrSql('RefFieldName', row, dbType));
appendStr(sqlProp, getStrSql('RefSearchWhere', row, dbType));
appendStr(sqlProp, getStrSql('RefEditWhere', row, dbType));
appendStr(sqlProp, getStrSql('RefSeparator', row, dbType));
appendStr(sqlProp, getStrSql('RefCols', row, dbType));
appendStr(sqlProp, getStrSql('IsEditable', row, dbType));
appendStr(sqlProp, getStrSql('IsCalc', row, dbType));
appendStr(sqlProp, getStrSql('IsRequired', row, dbType));
appendStr(sqlProp, getStrSql('IsQrySele', row, dbType));
appendStr(sqlProp, getStrSql('IsEditLimit', row, dbType));
appendStr(sqlProp, getStrSql('StatType', row, dbType));
appendStr(sqlProp, getStrSql('IsZeroSpace', row, dbType));
appendStr(sqlProp, getStrSql('IsEmptyField', row, dbType));
appendStr(sqlProp, getStrSql('SetRule', row, dbType));
appendStr(sqlProp, getStrSql('DataRightCode', row, dbType));
appendStr(sqlProp, getStrSql('DataRightType', row, dbType));
appendStr(sqlProp, getStrSql('Header', row, dbType));
appendStr(sqlProp, getStrSql('Precision', row, dbType));
appendStr(sqlProp, getStrSql('ExtParams', row, dbType));
appendStr(sqlProp, getStrSql('KeyBoardType', row, dbType), true);
sqlProp[0] += ");";
sqlProps += "\n";
sqlProps += sqlProp[0];
}
;
//合成最后的脚本
var dictScript = dictScriptTpl.replace(/#OBJCODE/g, objRow['UIObjCode']);
dictScript = dictScript.replace(/#OBJNAME/g, objRow['UIObjName']);
dictScript = dictScript.replace('#OBJ', sqlObj);
dictScript = dictScript.replace('#PROP', sqlProps);
self.$txtScript.val(dictScript);
};
//获取字符型存储过程的字符串
function getStrSql(name, row, dbType) {
if (dbType === 'oracle') {
return "ps_" + name + "=>" + getSqlValue(row[name]);
} else {
return getSqlValue(row[name]);
}
}
function getSqlValue(value) {
if (value == null) {
return null;
}
if (value || value == 0) {
var str = value.toString();
return "'" + str.replace(/\'/g, "''") + "'";
} else if (dbType === 'mysql') {
return value;
}
}
//获取数字型存储过程的字符串
function getNumSql(name, row, dbType) {
var value = row[name];
if (dbType === 'oracle') {
if (value || value == 0) {
return "pi_" + name + "=>" + value;
} else {
return "pi_" + name + "=>null";
}
} else if (dbType === 'mysql') {
if (value || value == 0) {
return value;
} else {
return "null";
}
}
}
function appendStr(src, str, noDot) {
src[0] = src[0] + str;
if (!noDot) {
src[0] += ',';
}
}
return Window;
})