/** * An 'interface' for undoable actions, implemented by classes that specify * how to handle action * * * @this {FigureCreateCommand} * @constructor * @param {Function} factoryFunction - the function that will create the {Figure}. It will be local copy (of original pointer) * @param {Number} x - the x coordinates * @param {Number} y - the x coordinates * @author Alex * @author Artyom Pokatilov */ function FigureCreateCommand(factoryFunction, x, y) { this.oType = 'FigureCreateCommand'; /**Any sequence of many mergeable actions can be packed by the history*/ this.mergeable = false; this.factoryFunction = factoryFunction; this.x = x; this.y = y; this.firstExecute = true; this.figureId = null; } FigureCreateCommand.prototype = { /**This method got called every time the Command must execute*/ execute: function () { if (createFigureName == "FlowChart" || createFigureName == "ThreadDtl" || createFigureName == "SubFlowDtl" || createFigureName == "FrmCheck") { var funIsExist = this.IsExist; var isExit = funIsExist(createFigureName); if (isExit == true) { $.messager.alert("错误", "@已存在ID为(" + createFigureName + ")的元素,不允许添加同名元素!", "error"); return false; } } if (this.firstExecute) { var canAddFigure = true; //是否拖上去之后,就立刻创建? //create figure var createdFigure = this.factoryFunction(this.x, this.y); //CCForm private Property createdFigure.CCForm_Shape = createFigureName; //move it into position createdFigure.transform(Matrix.translationMatrix(this.x - createdFigure.rotationCoords[0].x, this.y - createdFigure.rotationCoords[0].y)) createdFigure.style.lineWidth = defaultLineWidth; //ccflow business logic switch (createFigureName) { case CCForm_Controls.Image: canAddFigure = false; this.DataImgCreate(createdFigure, this.x, this.y); //createdFigure.CCForm_MyPK = Util.NewGUID(); break; case CCForm_Controls.Label: case CCForm_Controls.Button: createdFigure.CCForm_MyPK = Util.NewGUID(); this.ButtonCreate(createdFigure, this.x, this.y); break; case CCForm_Controls.HyperLink: createdFigure.CCForm_MyPK = Util.NewGUID(); this.HyperLinkCreate(createdFigure, this.x, this.y); break; case CCForm_Controls.TextBox: case CCForm_Controls.TextBoxInt: case CCForm_Controls.TextBoxFloat: case CCForm_Controls.TextBoxMoney: case CCForm_Controls.Date: case CCForm_Controls.DateTime: case CCForm_Controls.CheckBox: //case "HandSiganture": canAddFigure = false; this.DataFieldCreate(createdFigure, this.x, this.y); break; case CCForm_Controls.ListBox: case CCForm_Controls.HiddendField: alert('目前还没有对{' + createFigureName + '}提供该控件的支持.'); return; case CCForm_Controls.DropDownListEnum: //枚举类型. canAddFigure = false; // 需要弹出对话框创建. this.RadioButtonCreate(createdFigure, this.x, this.y, 'DDL'); break; case CCForm_Controls.RadioButton: canAddFigure = false; // 需要弹出对话框创建. this.RadioButtonCreate(createdFigure, this.x, this.y, 'RB'); break; case CCForm_Controls.DropDownListTable: //枚举类型. canAddFigure = false; // 需要弹出对话框创建. this.DropDownListTableCreate(createdFigure, this.x, this.y); break; case "Fieldset": case "HandSiganture": case "iFrame": case CCForm_Controls.Dtl: //明细表. case CCForm_Controls.AthMulti: //多附件. case CCForm_Controls.AthSingle: //单附件. case CCForm_Controls.AthImg: //图片附件. 以上控件都是用通用的 No,Name 数据框. canAddFigure = false; // 需要弹出对话框创建. this.PublicNoNameCtrlCreate(createdFigure, this.x, this.y, createFigureName); break; case "CheckGroup": alert('该功能没有实现' + createFigureName + ' 需要连续创建三个字段.'); break; //case CCForm_Controls.FrmCheck: //审核组件 //case CCForm_Controls.FrmCheck: // 审核组件. //case CCForm_Controls.FlowChart: //轨迹图. //case CCForm_Controls.SubFlowDtl: //子流程. //case CCForm_Controls.ThreadDtl: //子线城. case "FrmCheck": // 审核组件. case "FlowChart": //轨迹图. case "SubFlowDtl": //子流程. case "ThreadDtl": //子线城. // alert(createFigureName); // if (funIsExist(createFigureName) == true) { // //$.messager.alert("错误", "已存在ID为(" + frmVal.KeyOfEn + ")的元素,不允许添加同名元素!", "error"); // // alert('该控件已经存在' + createFigureName); // return; // } //名称都是独立的. createdFigure.CCForm_MyPK = createFigureName; this.FlowFieldCreate(createdFigure, this.x, this.y, createFigureName); break; default: //按照通用的接受编号,名称的方式来创建. alert('没有判断的控件类型{' + createFigureName + '},或者该功能为实现。'); return; } if (canAddFigure == true) { //store id for later use //TODO: maybe we should try to recreate it with same ID (in case further undo will recreate objects linked to this) this.figureId = createdFigure.id; //add to STACK STACK.figureAdd(createdFigure); //make this the selected figure selectedFigureId = createdFigure.id; //set up it's editor setUpEditPanel(createdFigure); //move to figure selected state state = STATE_FIGURE_SELECTED; } this.firstExecute = false; } else { //redo throw "Not implemented"; } }, ButtonCreate: function (createdFigure, x, y) { // 定义参数,让其保存到数据库里。 var btn = new Entity("BP.Sys.FrmBtn"); btn.MyPK = createdFigure.CCForm_MyPK; btn.FK_MapData = CCForm_FK_MapData; btn.Lab = "Btn"; btn.EventType = 2; btn.EventContext = ""; btn.X = x; btn.Y = y; btn.Insert(); }, HyperLinkCreate: function (createdFigure, x, y) { // 定义参数,让其保存到数据库里。 var frmLink = new Entity("BP.Sys.FrmLink"); frmLink.MyPK = createdFigure.CCForm_MyPK; frmLink.FK_MapData = CCForm_FK_MapData; frmLink.Target = "_blank"; frmLink.Lab = '我的超链接'; frmLink.X = x; frmLink.Y = y; frmLink.Insert(); }, DataImgCreate: function (createdFigure, x, y) { var dgId = "iframeImage"; var url = "DialogCtr/FrmImage.htm?DataType=" + createFigureName + "&s=" + Math.random(); var funIsExist = this.IsExist; OpenEasyUiDialog(url, dgId, '新建图片字段', 600, 394, 'icon-new', true, function () { var win = document.getElementById(dgId).contentWindow; var frmVal = win.GetFrmInfo(); if (frmVal.Name == null || frmVal.Name.length == 0) { $.messager.alert('错误', '字段名称不能为空。', 'error'); return false; } if (frmVal.KeyOfEn == null || frmVal.KeyOfEn.length == 0) { $.messager.alert('错误', '英文字段不能为空。', 'error'); return false; } //判断主键是否存在 var isExit = funIsExist(frmVal.KeyOfEn); if (isExit == true) { $.messager.alert("错误", "已存在ID为(" + frmVal.KeyOfEn + ")的元素,不允许添加同名元素!", "error"); return false; } // //根据信息创建不同类型的数字控件 var transField = new TransFormDataField(createdFigure, frmVal, x, y); var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_CCFormDesigner"); handler.AddPara("FrmID", CCForm_FK_MapData); handler.AddPara("KeyOfEn", frmVal.KeyOfEn); handler.AddPara("Name", frmVal.Name); handler.AddPara("x", x); handler.AddPara("y", y); var data = handler.DoMethodReturnString("NewImage"); if (data.indexOf('err@') == 0) { alert(data); return; } alert('创建成功.'); transField.paint(); }, null); return false; }, /**创建数据字段**/ DataFieldCreate: function (createdFigure, x, y) { var dgId = "iframeTextBox"; var url = "DialogCtr/FrmTextBox.htm?DataType=" + createFigureName + "&s=" + Math.random(); // alert(mapData.PTableModel); //如果不允许自定义字段. if (mapData.PTableModel == "2") { url = "DialogCtr/FrmTextBoxChoseOneField.htm?FK_MapData=" + mapData.No + "&DataType=" + createFigureName + "&M=" + Math.random(); } // alert(url); var funIsExist = this.IsExist; OpenEasyUiDialog(url, dgId, '新建文本字段', 600, 394, 'icon-new', true, function (HidenFieldFun) { var win = document.getElementById(dgId).contentWindow; var frmVal = win.GetFrmInfo(); if (frmVal.Name == null || frmVal.Name.length == 0) { $.messager.alert('错误', '字段名称不能为空。', 'error'); return false; } if (frmVal.KeyOfEn == null || frmVal.KeyOfEn.length == 0) { $.messager.alert('错误', '英文字段不能为空。', 'error'); return false; } //判断主键是否存在 var isExit = funIsExist(frmVal.KeyOfEn); if (isExit == true) { $.messager.alert("错误", "已存在ID为(" + frmVal.KeyOfEn + ")的元素,不允许添加同名元素!", "error"); return false; } //控件数据类型 if (frmVal.FieldType == "1") { createdFigure.CCForm_Shape = "TextBoxStr"; } else if (frmVal.FieldType == "2") { createdFigure.CCForm_Shape = "TextBoxInt"; } else if (frmVal.FieldType == "3") { createdFigure.CCForm_Shape = "TextBoxFloat"; } else if (frmVal.FieldType == "4") { createdFigure.CCForm_Shape = "TextBoxBoolean"; } else if (frmVal.FieldType == "5") { createdFigure.CCForm_Shape = "TextBoxDouble"; } else if (frmVal.FieldType == "6") { createdFigure.CCForm_Shape = "TextBoxDate"; } else if (frmVal.FieldType == "7") { createdFigure.CCForm_Shape = "TextBoxDateTime"; } else if (frmVal.FieldType == "8") { createdFigure.CCForm_Shape = "TextBoxMoney"; } //如果为隐藏字段 if (frmVal.IsHidenField == true) { HidenFieldFun(frmVal,x,y); } else { //根据信息创建不同类型的数字控件 var transField = new TransFormDataField(createdFigure, frmVal, x, y); var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_CCFormDesigner"); handler.AddPara("FrmID", CCForm_FK_MapData); handler.AddPara("KeyOfEn", frmVal.KeyOfEn); handler.AddPara("Name", frmVal.Name); handler.AddPara("FieldType", frmVal.FieldType); handler.AddPara("x", x); handler.AddPara("y", y); var data = handler.DoMethodReturnString("NewField"); if (data.indexOf('err@') == 0) { alert(data); return; } transField.paint(); } }, this.HidenFieldCreate); return false; }, /**创建单选按钮**/ RadioButtonCreate: function (createdFigure, x, y, dotype) { var dgId = "iframeRadioButton"; //var url = "DialogCtr/FrmEnumeration.htm?DataType=&s=" + Math.random(); var pTableModel = mapData.PTableModel; var url = "DialogCtr/FrmEnumeration.htm?PTableModel=" + pTableModel + "&FK_MapData=" + mapData.No + "&s=" + Math.random(); var funIsExist = this.IsExist; var lab = '单选按钮枚举值'; if (dotype == 'DDL') lab = '下拉框枚举值'; OpenEasyUiDialog(url, dgId, lab, 650, 394, 'icon-new', true, function () { var win = document.getElementById(dgId).contentWindow; var frmVal = win.GetFrmInfo(); if (frmVal.Name == null || frmVal.Name.length == 0) { $.messager.alert('错误', '字段名称不能为空。', 'error'); return false; } if (frmVal.KeyOfEn == null || frmVal.KeyOfEn.length == 0) { $.messager.alert('错误', '英文字段不能为空。', 'error'); return false; } //判断主键是否存在 var isExit = funIsExist(frmVal.KeyOfEn); if (isExit == true) { $.messager.alert("错误", "@已存在ID为(" + frmVal.KeyOfEn + ")的元素,不允许添加同名元素!", "error"); return false; } if (dotype == "DDL") createdFigure.CCForm_Shape = "DropDownListEnum"; else createdFigure.CCForm_Shape = "RadioButton"; //根据信息创建不同类型的数字控件. var transField = new TransFormDataField(createdFigure, frmVal, x, y); // 定义参数,让其保存到数据库里。 var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_CCFormDesigner"); handler.AddPara("FK_MapData", CCForm_FK_MapData); handler.AddPara("KeyOfEn", frmVal.KeyOfEn); handler.AddPara("Name", frmVal.Name); handler.AddPara("UIBindKey", frmVal.UIBindKey); handler.AddPara("CtrlDoType", dotype); handler.AddPara("x", x); handler.AddPara("y", y); var data = handler.DoMethodReturnString("FrmEnumeration_NewEnumField"); if (data.indexOf('err@') == 0) { alert(data); return; } try { //开始画这个 - 元素. transField.paint(); } catch (e) { alert('画元素错误:' + e); } }, null); return false; }, /**通用的No,Name 明细表,多附件,单附件 存储**/ PublicNoNameCtrlCreate: function (createdFigure, x, y, ctrlType) { var dgId = "iframeRadioButton"; var url = "DialogCtr/PublicNoNameCtrlCreate.htm?FrmID=" + CCForm_FK_MapData + "&CtrlType=" + ctrlType + "&s=" + Math.random(); var funIsExist = this.IsExist; var lab = '创建从表'; var note = '