Importer.js 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.query = MWF.xApplication.query || {};
  3. MWF.xApplication.query.ImporterDesigner = MWF.xApplication.query.ImporterDesigner || {};
  4. MWF.APPDIPD = MWF.APPDIPD || MWF.xApplication.query.ImporterDesigner;
  5. MWF.xDesktop.requireApp("query.ViewDesigner", "View", null, false);
  6. MWF.xDesktop.requireApp("query.ImporterDesigner", "lp."+MWF.language, null, false);
  7. MWF.xDesktop.requireApp("query.ImporterDesigner", "Property", null, false);
  8. MWF.xApplication.query.ImporterDesigner.Importer = new Class({
  9. Extends: MWF.xApplication.query.ViewDesigner.View,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "isView": false,
  14. "showTab": true,
  15. "propertyPath": "../x_component_query_ImporterDesigner/$Importer/importer.html"
  16. },
  17. initialize: function(designer, data, options){
  18. this.setOptions(options);
  19. this.path = "../x_component_query_ImporterDesigner/$Importer/";
  20. this.cssPath = "../x_component_query_ImporterDesigner/$Importer/"+this.options.style+"/css.wcss";
  21. this._loadCss();
  22. this.designer = designer;
  23. this.data = data;
  24. if (!this.data.data) this.data.data = {};
  25. this.parseData();
  26. this.node = this.designer.designNode;
  27. //this.tab = this.designer.tab;
  28. this.areaNode = new Element("div.areaNode", {"styles": {"height": "100%", "overflow": "auto"}});
  29. //MWF.require("MWF.widget.ScrollBar", function(){
  30. // new MWF.widget.ScrollBar(this.areaNode, {"distance": 100});
  31. //}.bind(this));
  32. this.propertyListNode = this.designer.propertyDomArea;
  33. //this.propertyNode = this.designer.propertyContentArea;
  34. if(this.designer.application) this.data.applicationName = this.designer.application.name;
  35. if(this.designer.application) this.data.application = this.designer.application.id;
  36. this.isNewImportModel = (this.data.name) ? false : true;
  37. this.items = [];
  38. this.calculateItems = [];
  39. this.importer = this.view = this;
  40. this.autoSave();
  41. this.designer.addEvent("queryClose", function(){
  42. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  43. }.bind(this));
  44. },
  45. loadViewNodes: function(){
  46. debugger;
  47. this.viewAreaNode = new Element("div#viewAreaNode", {"styles": this.css.viewAreaNode}).inject(this.areaNode);
  48. this.viewTitleNode = new Element("div#viewTitleNode", {"styles": this.css.viewTitleNode}).inject(this.viewAreaNode);
  49. this.excelTitleNode = new Element("div#excelTitleNode", {
  50. "styles": this.css.excelTitleNode,
  51. "text" : this.designer.lp.columnField+":"
  52. }).inject(this.viewTitleNode);
  53. // this.refreshNode = new Element("div", {"styles": this.css.refreshNode}).inject(this.viewTitleNode);
  54. this.viewColumnNode = new Element("div", {"styles": {"overflow":"hidden"}}).inject(this.viewTitleNode);
  55. this.addColumnLeftNode = new Element("div", {"styles": this.css.addColumnLeftNode}).inject(this.viewColumnNode);
  56. this.addColumnNode = new Element("div", {"styles": this.css.addColumnNode}).inject(this.viewColumnNode);
  57. this.viewTitleContentNode = new Element("div", {"styles": this.css.viewTitleContentNode}).inject(this.viewColumnNode);
  58. this.autoAddColumnsNode = new Element("div.autoAddColumnsNode", {
  59. styles: this.css.autoAddColumnsNode,
  60. title: this.designer.lp.autoAddColumns
  61. }).inject(this.viewTitleContentNode);
  62. if( this.json.type !== 'dynamicTable' || (this.json.data.columnList && this.json.data.columnList.length) ){
  63. this.autoAddColumnsNode.hide();
  64. }
  65. this.viewTitleTableNode = new Element("table", {
  66. "styles": this.css.viewTitleTableNode,
  67. "border": "0px",
  68. "cellPadding": "0",
  69. "cellSpacing": "0"
  70. }).inject(this.viewTitleContentNode);
  71. this.viewTitleTrNode = new Element("tr", {"styles": this.css.viewTitleTrNode}).inject(this.viewTitleTableNode);
  72. this.viewContentScrollNode = new Element("div", {"styles": this.css.viewContentScrollNode}).inject(this.viewAreaNode);
  73. this.viewContentNode = new Element("div", {"styles": this.css.viewContentNode}).inject(this.viewContentScrollNode);
  74. // MWF.require("MWF.widget.ScrollBar", function(){
  75. // new MWF.widget.ScrollBar(this.viewContentScrollNode, {"style": "view", "distance": 100, "indent": false});
  76. // }.bind(this));
  77. // this.contentLeftNode = new Element("div", {"styles": this.css.contentLeftNode}).inject(this.viewContentNode);
  78. // this.contentRightNode = new Element("div", {"styles": this.css.contentRightNode}).inject(this.viewContentNode);
  79. this.calculateTitleNode = new Element("div#calculateTitleNode", {
  80. "styles": this.css.calculateTitleNode,
  81. "text" : this.designer.lp.calculateField+":"
  82. }).inject(this.viewContentNode);
  83. this.addCalculateFieldNode = new Element("div#addCalculateFieldNode", {
  84. "styles": this.css.addCalculateFieldNode,
  85. }).inject(this.calculateTitleNode);
  86. if(this.json.type !== "dynamicTable"){
  87. this.addCalculateFieldNode.hide();
  88. }
  89. this.viewContentBodyNode = new Element("div", {"styles": this.css.viewContentBodyNode}).inject(this.viewContentNode);
  90. // this.viewContentTableNode = new Element("table", {
  91. // "styles": this.css.viewContentTableNode,
  92. // "border": "0px",
  93. // "cellPadding": "0",
  94. // "cellSpacing": "0"
  95. // }).inject(this.viewContentBodyNode);
  96. },
  97. autoSave: function(){
  98. this.autoSaveTimerID = window.setInterval(function(){
  99. if (!this.autoSaveCheckNode) this.autoSaveCheckNode = this.designer.contentToolbarNode.getElement("#MWFDictionaryAutoSaveCheck");
  100. if (this.autoSaveCheckNode){
  101. if (this.autoSaveCheckNode.get("checked")){
  102. this.save();
  103. }
  104. }
  105. }.bind(this), 60000);
  106. },
  107. parseData: function(){
  108. debugger;
  109. if( o2.typeOf(this.data.data)==="string"){
  110. this.data.data = JSON.parse(this.data.data);
  111. }
  112. this.json = this.data;
  113. if (!this.json.data )this.json.data = {};
  114. if (!this.json.data.calculateFieldList) this.json.data.calculateFieldList = [];
  115. if (!this.json.data.columnList) this.json.data.columnList = [];
  116. if( !this.json.data.events ){
  117. var url = "../x_component_query_ImporterDesigner/$Importer/importer.json";
  118. MWF.getJSON(url, {
  119. "onSuccess": function(obj){
  120. this.json.data.events = obj.data.events;
  121. }.bind(this),
  122. "onerror": function(text){
  123. this.notice(text, "error");
  124. }.bind(this),
  125. "onRequestFailure": function(xhr){
  126. this.notice(xhr.responseText, "error");
  127. }.bind(this)
  128. },false);
  129. }
  130. },
  131. showProperty: function(){
  132. if (!this.property){
  133. this.property = new MWF.xApplication.query.ImporterDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  134. "path": this.options.propertyPath,
  135. "onPostLoad": function(){
  136. this.property.show();
  137. }.bind(this)
  138. });
  139. this.property.load();
  140. }else{
  141. this.property.show();
  142. }
  143. },
  144. hideProperty: function(){
  145. if (this.property) this.property.hide();
  146. },
  147. load : function(){
  148. this.setAreaNodeSize();
  149. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  150. this.areaNode.inject(this.node);
  151. this.designer.viewListAreaNode.getChildren().each(function(node){
  152. var importer = node.retrieve("importer");
  153. if (importer && importer.id==this.data.id){
  154. if (this.designer.currentListViewItem){
  155. this.designer.currentListViewItem.setStyles(this.designer.css.listViewItem);
  156. }
  157. node.setStyles(this.designer.css.listViewItem_current);
  158. this.designer.currentListViewItem = node;
  159. this.lisNode = node;
  160. }
  161. }.bind(this));
  162. this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
  163. this.loadView();
  164. this.selected();
  165. this.setEvent();
  166. //if (this.options.showTab) this.page.showTabIm();
  167. this.setViewWidth();
  168. this.designer.addEvent("resize", this.setViewWidth.bind(this));
  169. this.fireEvent("postLoad");
  170. },
  171. setEvent: function(){
  172. this.areaNode.addEvent("click", this.selected.bind(this));
  173. // this.refreshNode.addEvent("click", function(e){
  174. // // this.loadViewData();
  175. // e.stopPropagation();
  176. // }.bind(this));
  177. this.addColumnLeftNode.addEvent("click", function(e){
  178. this.addColumn( true );
  179. e.stopPropagation();
  180. }.bind(this));
  181. this.addColumnNode.addEvent("click", function(e){
  182. this.addColumn();
  183. e.stopPropagation();
  184. }.bind(this));
  185. this.addCalculateFieldNode.addEvent("click", function(e){
  186. this.addCalculateField();
  187. e.stopPropagation();
  188. }.bind(this));
  189. this.autoAddColumnsNode.addEvent("click", function (e) {
  190. this.autoAddColumns();
  191. e.stopPropagation();
  192. }.bind(this));
  193. },
  194. autoAddColumns: function(){
  195. if(this.json.type !== "dynamicTable")return;
  196. if( !this.json.data.dynamicTable || !this.json.data.dynamicTable.id )return;
  197. MWF.require("MWF.widget.UUID", null, false);
  198. debugger;
  199. var p = o2.Actions.load("x_query_assemble_designer").TableAction.get(this.json.data.dynamicTable.id, function(json){
  200. if (json){
  201. var dataJson = JSON.decode(json.data.data);
  202. return dataJson.fieldList || [];
  203. }
  204. }.bind(this));
  205. Promise.resolve(p).then(function (data){
  206. this.json.data.columnList = data.map( function ( field ) {
  207. return {
  208. "id": (new MWF.widget.UUID).id,
  209. "path": field.name,
  210. "displayName": field.description || field.name,
  211. "dataType_Querytable" : field.type,
  212. "dataType_CMSProcess": "string",
  213. "validFieldType" : true
  214. };
  215. }.bind(this));
  216. this.json.data.columnList.each(function (d, i) {
  217. this.items.push(new MWF.xApplication.query.ImporterDesigner.Importer.Column(d, this, null, i));
  218. }.bind(this));
  219. this.items.each( function (item, i) {
  220. item.resetIndex(i);
  221. });
  222. }.bind(this));
  223. },
  224. addCalculateField: function(){
  225. var id = (new MWF.widget.UUID).id;
  226. var json = {
  227. "id": id,
  228. "displayName": this.designer.lp.unnamed,
  229. };
  230. this.json.data.calculateFieldList.push(json);
  231. var field = new MWF.xApplication.query.ImporterDesigner.Importer.CalculateField(json, this, null);
  232. this.calculateItems.push(field);
  233. field.selected();
  234. },
  235. addColumn: function( addToLeft ){
  236. MWF.require("MWF.widget.UUID", function(){
  237. var id = (new MWF.widget.UUID).id;
  238. var json = {
  239. "id": id,
  240. "displayName": this.designer.lp.unnamed,
  241. };
  242. var column;
  243. if( !addToLeft || this.json.data.columnList.length === 0 ){
  244. this.json.data.columnList.push(json);
  245. column = new MWF.xApplication.query.ImporterDesigner.Importer.Column(json, this, null);
  246. this.items.push(column);
  247. }else{
  248. this.json.data.columnList.unshift(json);
  249. column = new MWF.xApplication.query.ImporterDesigner.Importer.Column(json, this, this.items[0]);
  250. this.items.unshift(column);
  251. }
  252. column.selected();
  253. // if (this.viewContentTableNode){
  254. // var trs = this.viewContentTableNode.getElements("tr");
  255. // trs.each(function(tr){
  256. // new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  257. // }.bind(this));
  258. // //this.setContentColumnWidth();
  259. // }
  260. this.items.each( function (item, i) {
  261. item.resetIndex(i);
  262. });
  263. this.setViewWidth();
  264. if( addToLeft ){
  265. this.addColumnLeftNode.scrollIntoView(false);
  266. }else{
  267. this.addColumnNode.scrollIntoView(false);
  268. }
  269. }.bind(this));
  270. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  271. },
  272. loadViewColumns: function(){
  273. // for (var i=0; i<10; i++){
  274. if (this.json.data.columnList) {
  275. this.json.data.columnList.each(function (json, i) {
  276. this.items.push(new MWF.xApplication.query.ImporterDesigner.Importer.Column(json, this, null, i));
  277. }.bind(this));
  278. }
  279. // }
  280. },
  281. loadViewCalculateFields: function(){
  282. // for (var i=0; i<10; i++){
  283. if (this.json.data.calculateFieldList) {
  284. this.json.data.calculateFieldList.each(function (json, i) {
  285. this.calculateItems.push(new MWF.xApplication.query.ImporterDesigner.Importer.CalculateField(json, this, null, i));
  286. }.bind(this));
  287. }
  288. // }
  289. },
  290. // loadViewSelectAllNode : function(){
  291. // var _self = this;
  292. // var td = new Element("td.viewTitleCheckboxTd",{ "styles": this.css.viewTitleColumnAreaNode }).inject( this.viewTitleTrNode );
  293. // td.setStyles({
  294. // "width":"30px", "text-align" : "center",
  295. // "display" : this.json.data.selectAllEnable ? "table-cell" : "none"
  296. // });
  297. // new Element("input",{
  298. // "type" : "checkbox",
  299. // "events" : {
  300. // "change" : function(){
  301. // _self.viewContentTableNode.getElements(".viewContentCheckbox").set("checked", this.checked )
  302. // }
  303. // }
  304. // }).inject(td);
  305. // },
  306. // createViewCheckboxTd : function( tr ){
  307. // var td = new Element("td.viewContentCheckboxTd", {"styles": this.css.viewContentTdNode}).inject(tr, "top");
  308. // td.setStyles({
  309. // "width":"30px", "text-align" : "center",
  310. // "display" : this.json.data.selectAllEnable ? "table-cell" : "none"
  311. // });
  312. // new Element("input.viewContentCheckbox",{
  313. // "type" : "checkbox"
  314. // }).inject(td);
  315. // },
  316. loadView: function(){
  317. this.loadViewNodes();
  318. //this.loadViewSelectAllNode();
  319. this.loadViewColumns();
  320. this.loadViewCalculateFields();
  321. // this.addTopItemNode.addEvent("click", this.addTopItem.bind(this));
  322. },
  323. setViewWidth: function(){
  324. // window.setTimeout(function() {
  325. if (!this.viewAreaNode) return;
  326. this.viewAreaNode.setStyle("width", "auto");
  327. this.viewTitleNode.setStyle("width", "auto");
  328. var s1 = this.viewTitleTableNode.getSize();
  329. var m1 = this.viewTitleNode.getStyle("margin-left");
  330. var m2 = this.viewTitleNode.getStyle("margin-right");
  331. var s2 = this.addColumnLeftNode.getSize();
  332. var s3 = this.addColumnNode.getSize();
  333. var width = s1.x + s2.x + s2.x - m1.toFloat() - m2.toFloat();
  334. var size = this.areaNode.getSize();
  335. if (width > size.x) {
  336. this.viewTitleNode.setStyle("width", "" + width + "px");
  337. this.viewAreaNode.setStyle("width", "" + width + "px");
  338. } else {
  339. this.viewTitleNode.setStyle("width", "" + size.x + "px");
  340. this.viewAreaNode.setStyle("width", "" + size.x + "px");
  341. }
  342. this.setContentColumnWidth();
  343. this.setContentHeight();
  344. // }.bind(this), 10);
  345. },
  346. setContentHeight: function(){
  347. var size = this.areaNode.getSize();
  348. var titleSize = this.viewTitleNode.getSize();
  349. var calculateTitleNodeSize = this.calculateTitleNode ? this.calculateTitleNode.getSize() : {x:0, y:0};
  350. var height = size.y-titleSize.y-calculateTitleNodeSize.y-2;
  351. // this.viewContentScrollNode.setStyle("height", height);
  352. // var contentSize = this.viewContentBodyNode.getSize();
  353. // if (height<contentSize.y) height = contentSize.y+10;
  354. // this.viewContentNode.setStyle("height", height);
  355. },
  356. setAreaNodeSize: function(){
  357. },
  358. saveSilence: function(callback){
  359. if (!this.data.name){
  360. this.designer.notice(this.designer.lp.notice.inputName, "error");
  361. return false;
  362. }
  363. // var list;
  364. // if( this.data.data && this.data.data.where ){
  365. // if( this.data.data.where.creatorIdentityList ){
  366. // list = this.data.data.where.creatorIdentityList;
  367. // for( var i=0; i< list.length ; i++){
  368. // if( typeOf( list[i] ) === "object" )list[i] = list[i].name || "";
  369. // }
  370. // }
  371. // if( this.data.data.where.creatorPersonList ){
  372. // list = this.data.data.where.creatorPersonList;
  373. // for( var i=0; i< list.length ; i++){
  374. // if( typeOf( list[i] ) === "object" )list[i] = list[i].name || "";
  375. // }
  376. // }
  377. // if( this.data.data.where.creatorUnitList ){
  378. // list = this.data.data.where.creatorIdentityList;
  379. // for( var i=0; i< list.length ; i++){
  380. // if( typeOf( list[i] ) === "object" )list[i] = list[i].name || "";
  381. // }
  382. // }
  383. // }
  384. this.designer.actions.saveImportModel(this.data, function(json){
  385. this.data.id = json.data.id;
  386. this.isNewImportModel = false;
  387. //this.page.textNode.set("text", this.data.name);
  388. if (this.lisNode) {
  389. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  390. }
  391. if (callback) callback();
  392. }.bind(this));
  393. },
  394. save: function(callback){
  395. debugger;
  396. if (!this.data.name){
  397. this.designer.notice(this.designer.lp.notice.inputName, "error");
  398. return false;
  399. }
  400. if( !this.json.type ){
  401. this.designer.notice(this.designer.lp.notice.inputType, "error");
  402. return false;
  403. }
  404. if (this.json.type==="cms"){
  405. if( !this.json.data.category || !this.json.data.category.id ){
  406. this.designer.notice(this.designer.lp.notice.inputCategory, "error");
  407. return false;
  408. }
  409. }else if(this.json.type==="process"){
  410. if( !this.json.data.process || !this.json.data.process.id ){
  411. this.designer.notice(this.designer.lp.notice.inputProcess, "error");
  412. return false;
  413. }
  414. }else if(this.json.type==="dynamicTable"){
  415. if( !this.json.data.dynamicTable || !this.json.data.dynamicTable.name ){
  416. this.designer.notice(this.designer.lp.notice.inputTable, "error");
  417. return false;
  418. }
  419. }
  420. var fieldArr=[], textArr=[], data = this.json.data;
  421. var fieldArr2 = [], textArr2 = [];
  422. if (this.json.type==="cms"){
  423. if( data.documentPublisher !== "importer" ){
  424. fieldArr.push("documentPublisherField");
  425. textArr.push("publisher");
  426. }
  427. if( data.documentPublishTime !== "importer" ){
  428. fieldArr.push("documentPublisherTimeField");
  429. textArr.push("publishTime");
  430. }
  431. }else if(this.json.type==="process"){
  432. if( data.processDrafter !== "importer" ){
  433. fieldArr.push("processDrafterField");
  434. textArr.push("processDrafter");
  435. }
  436. if( data.processStatus === "completed" ){
  437. fieldArr = fieldArr.concat(["processStartTimeField", "processCompleteTimeField"]);
  438. textArr = textArr.concat([ "startTimeField", "completeTimeField"]);
  439. fieldArr2.push("processForm");
  440. textArr2.push("selectForm");
  441. }
  442. }
  443. var noteTextArr = [];
  444. var lp = this.view.designer.lp.propertyTemplate;
  445. if( fieldArr.length || fieldArr2.length){
  446. fieldArr2.each( function(field, i) {
  447. if (!data[field])noteTextArr.push(lp[textArr2[i]]);
  448. });
  449. var columnList = [].concat(data.columnList, data.calculateFieldList);
  450. fieldArr.each( function(field, i){
  451. if( !data[field] ){
  452. noteTextArr.push( lp[textArr[i]] );
  453. }else {
  454. var path = data[field];
  455. var flag = columnList.some(function (c) { return c.path === path;});
  456. if(!flag)noteTextArr.push( lp[textArr[i]] );
  457. }
  458. }.bind(this));
  459. }
  460. if( noteTextArr.length ){
  461. var _self = this;
  462. var text = MWF.APPDIPD.LP.notice.someFieldIsEmpty.replace("{text}", noteTextArr.join("、"));
  463. this.designer.confirm("warn", this.node, MWF.APPDIPD.LP.notice.saveNotice, text, 300, 120, function(){
  464. _self._save();
  465. this.close();
  466. }, function(){
  467. this.close();
  468. }, null);
  469. }else{
  470. this._save(callback)
  471. }
  472. },
  473. _save: function(callback){
  474. //if (this.designer.tab.showPage==this.page){
  475. debugger;
  476. // var list;
  477. // if( this.data.data && this.data.data.where ){
  478. // if( this.data.data.where.creatorIdentityList ){
  479. // list = this.data.data.where.creatorIdentityList;
  480. // for( var i=0; i< list.length ; i++){
  481. // if( typeOf( list[i] ) === "object" )list[i] = list[i].name || "";
  482. // }
  483. // }
  484. // if( this.data.data.where.creatorPersonList ){
  485. // list = this.data.data.where.creatorPersonList;
  486. // for( var i=0; i< list.length ; i++){
  487. // if( typeOf( list[i] ) === "object" )list[i] = list[i].name || "";
  488. // }
  489. // }
  490. // if( this.data.data.where.creatorUnitList ){
  491. // list = this.data.data.where.creatorUnitList;
  492. // for( var i=0; i< list.length ; i++){
  493. // if( typeOf( list[i] ) === "object" )list[i] = list[i].name || "";
  494. // }
  495. // }
  496. // }
  497. this.designer.actions.saveImportModel(this.data, function(json){
  498. this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  499. this.isNewImportModel = false;
  500. this.data.id = json.data.id;
  501. //this.page.textNode.set("text", this.data.name);
  502. if (this.lisNode) {
  503. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  504. }
  505. if (callback) callback();
  506. }.bind(this));
  507. },
  508. explode: function(){},
  509. implode: function(){},
  510. _setEditStyle: function(name, input, oldValue) {
  511. switch( name ){
  512. case 'data.process':
  513. this.property.loadFormSelect();
  514. break;
  515. case 'type':
  516. if(this.autoAddColumnsNode){
  517. if( this.json.type !== 'dynamicTable' || (this.json.data.columnList && this.json.data.columnList.length) ){
  518. this.autoAddColumnsNode.hide();
  519. }else{
  520. this.autoAddColumnsNode.show();
  521. }
  522. }
  523. }
  524. },
  525. reloadMaplist: function(){
  526. if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this));
  527. },
  528. setCustomStyles: function(){
  529. // this.items.each( function( item ){
  530. // item.setCustomStyles()
  531. // }.bind(this));
  532. },
  533. saveAs: function(){
  534. var form = new MWF.xApplication.query.ImporterDesigner.Importer.NewNameForm(this, {
  535. name : this.data.name + "_" + MWF.xApplication.query.ImporterDesigner.LP.copy,
  536. query : this.data.query || this.data.application,
  537. queryName : this.data.queryName || this.data.applicationName
  538. }, {
  539. onSave : function( data, callback ){
  540. this._saveAs( data, callback );
  541. }.bind(this)
  542. }, {
  543. app: this.designer
  544. });
  545. form.edit()
  546. },
  547. _saveAs : function( data , callback){
  548. var _self = this;
  549. var d = this.cloneObject( this.data );
  550. d.isNewImportModel = true;
  551. d.id = this.designer.actions.getUUID();
  552. d.name = data.name;
  553. d.alias = "";
  554. d.query = data.query;
  555. d.queryName = data.queryName;
  556. d.application = data.query;
  557. d.applicationName = data.queryName;
  558. d.pid = d.id + d.id;
  559. delete d[this.data.id+"viewFilterType"];
  560. d[d.id+"viewFilterType"]="custom";
  561. d.data.columnList.each( function( entry ){
  562. entry.id = (new MWF.widget.UUID).id;
  563. }.bind(this));
  564. this.designer.actions.saveImportModel(d, function(json){
  565. this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  566. if (callback) callback();
  567. }.bind(this));
  568. },
  569. checkUniqueSetting: function (column, name , value) {
  570. debugger;
  571. if (value !== "true")return;
  572. ([].concat(this.items, this.calculateItems)).each(function (col) {
  573. if( col !== column && (col.json[name] === "true" || col.json[name] === true) ){
  574. col.json[name] = false;
  575. if(col.property){
  576. var radios = col.property.propertyContent.getElements("input[name$='"+name+"']"); //$匹配结尾
  577. radios.each(function (r) {
  578. if (r.value === "true") r.set("checked", false);
  579. if (r.value === "false") r.set("checked", true);
  580. });
  581. }
  582. }
  583. });
  584. },
  585. preview: function(){
  586. if( this.isNewView ){
  587. this.designer.notice( this.designer.lp.saveViewNotice, "error" );
  588. return;
  589. }
  590. this.saveSilence( function () {
  591. var url = "../x_desktop/app.html?app=query.Query&status=";
  592. url += JSON.stringify({
  593. id : this.data.application,
  594. importerId : this.data.id
  595. });
  596. window.open(o2.filterUrl(url),"_blank");
  597. }.bind(this));
  598. },
  599. });
  600. MWF.xApplication.query.ImporterDesigner.Importer.Column = new Class({
  601. Extends: MWF.xApplication.query.ViewDesigner.View.Column,
  602. initialize: function(json, view, next, index){
  603. this.propertyPath = "../x_component_query_ImporterDesigner/$Importer/column.html";
  604. this.view = view;
  605. this.json = json;
  606. this.next = next;
  607. this.index = index;
  608. this.css = this.view.css;
  609. this.content = this.view.viewTitleTrNode;
  610. this.domListNode = this.view.domListNode;
  611. this.view.autoAddColumnsNode.hide();
  612. this.load();
  613. },
  614. load: function(){
  615. if( !this.json.events ){
  616. this.loadDefaultJson(function () {
  617. this._load()
  618. }.bind(this))
  619. }else{
  620. this._load();
  621. }
  622. },
  623. _load: function(){
  624. this.areaNode = new Element("td", {"styles": this.css.viewTitleColumnAreaNode});
  625. this.areaNode.store("column", this);
  626. if (this.next){
  627. this.areaNode.inject(this.next.areaNode, "before");
  628. }else{
  629. this.areaNode.inject(this.content);
  630. }
  631. this.node = new Element("div", {
  632. "styles": this.css.viewTitleColumnNode
  633. }).inject(this.areaNode);
  634. var colName = this.index2ColumnName( this.index );
  635. colName = colName ? ( colName + ": " ) : "";
  636. var displayName;
  637. if( this.json.path && (!this.json.displayName || this.json.displayName === this.view.designer.lp.unnamed) ){
  638. displayName = this.json.path;
  639. }else{
  640. displayName = this.json.displayName
  641. }
  642. this.textNode = new Element("div", {
  643. "styles": this.css.viewTitleColumnTextNode,
  644. "text": colName + displayName
  645. }).inject(this.node);
  646. this.createDomListItem();
  647. this._createIconAction();
  648. //if (!this.json.export) this.hideMode();
  649. this.setEvent();
  650. },
  651. loadDefaultJson: function(callback){
  652. this._loadDefaultJson(function (defaultColumnJson){
  653. for( var key in defaultColumnJson){
  654. if( !this.json[key] ){
  655. this.json[key] = defaultColumnJson[key];
  656. }
  657. }
  658. if (callback) callback(this.json);
  659. }.bind(this));
  660. },
  661. _loadDefaultJson: function (callback){
  662. if( this.view.defaultColumnJson ){
  663. if (callback) callback(Object.clone(this.view.defaultColumnJson));
  664. return;
  665. }
  666. var url = this.view.path+"column.json";
  667. MWF.getJSON(url, {
  668. "onSuccess": function(obj){
  669. this.view.defaultColumnJson = obj;
  670. if (callback) callback(Object.clone(this.view.defaultColumnJson));
  671. }.bind(this),
  672. "onerror": function(text){
  673. this.view.designer.notice(text, "error");
  674. }.bind(this),
  675. "onRequestFailure": function(xhr){
  676. this.view.designer.notice(xhr.responseText, "error");
  677. }.bind(this)
  678. }, false);
  679. },
  680. createDomListItem: function(){
  681. this.listNode = new Element("div", {"styles": this.css.cloumnListNode});
  682. if (this.next){
  683. this.listNode.inject(this.next.listNode, "before");
  684. }else{
  685. this.listNode.inject(this.domListNode);
  686. }
  687. var listIconNode = new Element("div", {"styles": this.css.cloumnListIconNode}).inject(this.listNode);
  688. var listTextNode = new Element("div", {"styles": this.css.cloumnListTextNode}).inject(this.listNode);
  689. this.resetTextNode();
  690. },
  691. setEvent: function(){
  692. this.node.addEvents({
  693. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  694. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.viewTitleColumnNode_over)}.bind(this),
  695. "mouseout": function(){if (!this.isSelected) if (this.isError){
  696. this.node.setStyles(this.css.viewTitleColumnNode_error)
  697. }else{
  698. this.node.setStyles(this.css.viewTitleColumnNode)
  699. }}.bind(this)
  700. });
  701. this.listNode.addEvents({
  702. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  703. "mouseover": function(){if (!this.isSelected) this.listNode.setStyles(this.css.cloumnListNode_over)}.bind(this),
  704. "mouseout": function(){if (!this.isSelected) this.listNode.setStyles(this.css.cloumnListNode)}.bind(this)
  705. });
  706. },
  707. _createIconAction: function(){
  708. if (!this.actionArea){
  709. this.actionArea = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.view.areaNode, "after");
  710. this._createAction({
  711. "name": "move",
  712. "icon": "move1.png",
  713. "event": "mousedown",
  714. "action": "move",
  715. "title": MWF.APPDIPD.LP.action.move
  716. });
  717. this._createAction({
  718. "name": "add",
  719. "icon": "add.png",
  720. "event": "click",
  721. "action": "addColumn",
  722. "title": MWF.APPDIPD.LP.action.add
  723. });
  724. this._createAction({
  725. "name": "delete",
  726. "icon": "delete1.png",
  727. "event": "click",
  728. "action": "delete",
  729. "title": MWF.APPDIPD.LP.action["delete"]
  730. });
  731. }
  732. },
  733. _createAction: function(action){
  734. var actionNode = new Element("div", {
  735. "styles": this.css.actionNodeStyles,
  736. "title": action.title
  737. }).inject(this.actionArea);
  738. actionNode.setStyle("background", "url("+this.view.path+this.view.options.style+"/action/"+action.icon+") no-repeat left center");
  739. actionNode.addEvent(action.event, function(e){
  740. this[action.action](e);
  741. }.bind(this));
  742. actionNode.addEvents({
  743. "mouseover": function(e){
  744. e.target.setStyle("border", "1px solid #999");
  745. }.bind(this),
  746. "mouseout": function(e){
  747. e.target.setStyle("border", "1px solid #F1F1F1");
  748. }.bind(this)
  749. });
  750. },
  751. showProperty: function(){
  752. if (!this.property){
  753. this.property = new MWF.xApplication.query.ImporterDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  754. "path": this.propertyPath,
  755. "onPostLoad": function(){
  756. this.property.show();
  757. var processDiv = this.property.propertyContent.getElements("#"+this.json.id+"dataPathSelectedProcessArea");
  758. var cmsDiv = this.property.propertyContent.getElements("#"+this.json.id+"dataPathSelectedCMSArea");
  759. if (this.view.json.type=="cms"){
  760. processDiv.setStyle("display", "none");
  761. cmsDiv.setStyle("display", "block");
  762. }else{
  763. processDiv.setStyle("display", "block");
  764. cmsDiv.setStyle("display", "none");
  765. }
  766. }.bind(this)
  767. });
  768. this.property.load();
  769. }else{
  770. this.property.show();
  771. }
  772. },
  773. "delete": function(e){
  774. var _self = this;
  775. if (!e) e = this.node;
  776. this.view.designer.confirm("warn", e, MWF.APPDIPD.LP.notice.deleteColumnTitle, MWF.APPDIPD.LP.notice.deleteColumn, 300, 120, function(){
  777. _self.destroy();
  778. this.close();
  779. }, function(){
  780. this.close();
  781. }, null);
  782. },
  783. _setEditStyle: function(name, input, oldValue){
  784. //column
  785. debugger;
  786. if (name==="displayName") {
  787. this.resetTextNode();
  788. this.view.property.loadSelectField();
  789. }
  790. if (name==="path") {
  791. this.resetTextNode();
  792. this.view.property.loadSelectField();
  793. }
  794. if (name==="selectType") this.resetTextNode();
  795. if (name==="attribute") this.resetTextNode();
  796. // if (["isTitle","isSummary","isPublisher","isProcessTitle","isProcessDrafter"].contains(name)){
  797. // this.view.checkUniqueSetting(this, name, input.get("value"));
  798. // }
  799. },
  800. resetTextNode: function( index ){
  801. var listText = (this.json.selectType=="attribute") ? (this.json.attribute || "") : (this.json.path || "");
  802. if (!listText) listText = "unnamed";
  803. var colName = this.index2ColumnName( index || this.index );
  804. colName = colName ? ( colName + ": " ) : "";
  805. var displayName;
  806. if( this.json.path && (!this.json.displayName || this.json.displayName === this.view.designer.lp.unnamed) ){
  807. displayName = this.json.path;
  808. }else{
  809. displayName = this.json.displayName
  810. }
  811. this.textNode.set("text", colName + displayName );
  812. this.listNode.getLast().set("text", this.json.displayName+"("+listText+")");
  813. },
  814. destroy: function(){
  815. if (this.view.currentSelectedModule==this) this.view.currentSelectedModule = null;
  816. if (this.actionArea) this.actionArea.destroy();
  817. if (this.listNode) this.listNode.destroy();
  818. if (this.property) this.property.propertyContent.destroy();
  819. var idx = this.view.items.indexOf(this);
  820. // if (this.view.viewContentTableNode){
  821. // var trs = this.view.viewContentTableNode.getElements("tr");
  822. // var isGroup = this.isGroupColumn();
  823. // trs.each(function(tr){
  824. // if( isGroup ){
  825. // if( tr.get("data-is-group") === "yes" ){
  826. // tr.destroy()
  827. // }
  828. // }else{
  829. // if( tr.get("data-is-group") !== "yes" ){
  830. // tr.deleteCell(idx);
  831. // }
  832. // }
  833. // }.bind(this));
  834. // }
  835. if (this.view.json.data.columnList) this.view.json.data.columnList.erase(this.json);
  836. // if (this.view.json.data.calculate) if (this.view.json.data.calculate.calculateList) this.view.json.data.calculate.calculateList.erase(this.json);
  837. this.view.items.erase(this);
  838. if (this.view.property) this.view.property.loadStatColumnSelect();
  839. this.areaNode.destroy();
  840. this.view.property.loadSelectField();
  841. this.view.selected();
  842. this.view.items.each( function (item, i) {
  843. item.resetIndex(i);
  844. });
  845. this.view.setViewWidth();
  846. this._destroy();
  847. MWF.release(this);
  848. delete this;
  849. },
  850. _destroy: function (){
  851. if( !this.view.json.data.columnList || !this.view.json.data.columnList.length ){
  852. this.view.autoAddColumnsNode.show();
  853. }
  854. },
  855. addColumn: function(e, data){
  856. MWF.require("MWF.widget.UUID", function(){
  857. var json;
  858. if (data){
  859. json = Object.clone(data);
  860. json.id = (new MWF.widget.UUID).id;
  861. }else{
  862. var id = (new MWF.widget.UUID).id;
  863. this._loadDefaultJson(function (defaultColumnJson){
  864. defaultColumnJson.id = id;
  865. defaultColumnJson.displayName = MWF.xApplication.query.ImporterDesigner.LP.unnamed;
  866. json = defaultColumnJson;
  867. }.bind(this));
  868. }
  869. var idx = this.view.json.data.columnList.indexOf(this.json);
  870. this.view.json.data.columnList.splice(idx, 0, json);
  871. var column = new MWF.xApplication.query.ImporterDesigner.Importer.Column(json, this.view, this);
  872. this.view.items.splice(idx, 0, column);
  873. column.selected();
  874. if (this.view.viewContentTableNode){
  875. var trs = this.view.viewContentTableNode.getElements("tr");
  876. trs.each(function(tr){
  877. var td = tr.insertCell(idx);
  878. td.setStyles(this.css.viewContentTdNode);
  879. }.bind(this));
  880. }
  881. this.view.items.each( function (item, i) {
  882. item.resetIndex(i);
  883. });
  884. this.view.setViewWidth();
  885. }.bind(this));
  886. },
  887. resetIndex : function( index ){
  888. this.index = index;
  889. this.resetTextNode();
  890. },
  891. index2ColumnName : function( index ){
  892. if( typeOf(index) !== "number" )return null;
  893. if (index < 0) return null;
  894. var num = 65;// A的Unicode码
  895. var colName = "";
  896. do {
  897. if (colName.length > 0)index--;
  898. var remainder = index % 26;
  899. colName = String.fromCharCode(remainder + num) + colName;
  900. index = (index - remainder) / 26;
  901. } while (index > 0);
  902. return colName;
  903. },
  904. move: function(e){
  905. var columnNodes = [];
  906. this.view.items.each(function(item){
  907. if (item!=this){
  908. columnNodes.push(item.areaNode);
  909. }
  910. }.bind(this));
  911. this._createMoveNode();
  912. this._setNodeMove(columnNodes, e);
  913. },
  914. _setNodeMove: function(droppables, e){
  915. this._setMoveNodePosition(e);
  916. var movePosition = this.moveNode.getPosition();
  917. var moveSize = this.moveNode.getSize();
  918. var contentPosition = this.content.getPosition();
  919. var contentSize = this.content.getSize();
  920. var nodeDrag = new Drag.Move(this.moveNode, {
  921. "droppables": droppables,
  922. "limit": {
  923. "x": [contentPosition.x, contentPosition.x+contentSize.x],
  924. "y": [movePosition.y, movePosition.y+moveSize.y]
  925. },
  926. "onEnter": function(dragging, inObj){
  927. if (!this.moveFlagNode) this.createMoveFlagNode();
  928. this.moveFlagNode.inject(inObj, "before");
  929. }.bind(this),
  930. "onLeave": function(dragging, inObj){
  931. if (this.moveFlagNode){
  932. this.moveFlagNode.dispose();
  933. }
  934. }.bind(this),
  935. "onDrop": function(dragging, inObj){
  936. if (inObj){
  937. this.areaNode.inject(inObj, "before");
  938. var column = inObj.retrieve("column");
  939. this.listNode.inject(column.listNode, "before");
  940. this.view.json.data.columnList.erase(this.json);
  941. this.view.items.erase(this);
  942. var idx = this.view.json.data.columnList.indexOf(column.json);
  943. this.view.json.data.columnList.splice(idx, 0, this.json);
  944. this.view.items.splice(idx, 0, this);
  945. if (this.moveNode) this.moveNode.destroy();
  946. if (this.moveFlagNode) this.moveFlagNode.destroy();
  947. this._setActionAreaPosition();
  948. this.view.items.each( function (item, i) {
  949. item.resetIndex(i);
  950. });
  951. }else{
  952. if (this.moveNode) this.moveNode.destroy();
  953. if (this.moveFlagNode) this.moveFlagNode.destroy();
  954. }
  955. }.bind(this),
  956. "onCancel": function(dragging){
  957. if (this.moveNode) this.moveNode.destroy();
  958. if (this.moveFlagNode) this.moveFlagNode.destroy();
  959. }.bind(this)
  960. });
  961. nodeDrag.start(e);
  962. }
  963. });
  964. MWF.xApplication.query.ImporterDesigner.Importer.CalculateField = new Class({
  965. Extends: MWF.QV$Module,
  966. initialize: function(json, view, next){
  967. this.propertyPath = "../x_component_query_ImporterDesigner/$Importer/calculateField.html";
  968. this.view = view;
  969. this.json = json;
  970. this.next = next;
  971. this.css = this.view.css;
  972. this.content = this.view.viewContentBodyNode;
  973. // this.domListNode = this.view.domListNode;
  974. this.load();
  975. },
  976. load: function(){
  977. if( !this.json.events ){
  978. this.loadDefaultJson(function () {
  979. this._load()
  980. }.bind(this))
  981. }else{
  982. this._load();
  983. }
  984. },
  985. _load: function(){
  986. this.areaNode = new Element("div", {"styles": this.css.viewCalculateFieldAreaNode});
  987. this.areaNode.store("column", this);
  988. if (this.next){
  989. this.areaNode.inject(this.next.areaNode, "before");
  990. }else{
  991. this.areaNode.inject(this.content);
  992. }
  993. this.node = new Element("div", {
  994. "styles": this.css.viewCalculateFieldNode
  995. }).inject(this.areaNode);
  996. this.textNode = new Element("div", {
  997. "styles": this.css.viewCalculateFieldTextNode,
  998. "text": this.json.displayName
  999. }).inject(this.node);
  1000. // this.createDomListItem();
  1001. this._createIconAction();
  1002. this.setEvent();
  1003. this.setCustomStyles();
  1004. },
  1005. loadDefaultJson: function(callback){
  1006. this._loadDefaultJson(function (defaultCalculateFieldJson){
  1007. for( var key in defaultCalculateFieldJson){
  1008. if( !this.json[key] ){
  1009. this.json[key] = defaultCalculateFieldJson[key];
  1010. }
  1011. }
  1012. if (callback) callback(this.json);
  1013. }.bind(this))
  1014. },
  1015. _loadDefaultJson: function(callback){
  1016. if( this.view.defaultCalculateFieldJson ){
  1017. if (callback) callback( Object.clone(this.view.defaultCalculateFieldJson) );
  1018. return;
  1019. }
  1020. var url = this.view.path+"calculateField.json";
  1021. MWF.getJSON(url, {
  1022. "onSuccess": function(obj){
  1023. this.view.defaultCalculateFieldJson = obj;
  1024. if (callback) callback( Object.clone(this.view.defaultCalculateFieldJson) );
  1025. }.bind(this),
  1026. "onerror": function(text){
  1027. this.view.designer.notice(text, "error");
  1028. }.bind(this),
  1029. "onRequestFailure": function(xhr){
  1030. this.view.designer.notice(xhr.responseText, "error");
  1031. }.bind(this)
  1032. }, false);
  1033. },
  1034. setEvent: function(){
  1035. this.node.addEvents({
  1036. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  1037. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.viewTitleColumnNode_over)}.bind(this),
  1038. "mouseout": function(){if (!this.isSelected) if (this.isError){
  1039. this.node.setStyles(this.css.viewTitleColumnNode_error)
  1040. }else{
  1041. this.node.setStyles(this.css.viewTitleColumnNode)
  1042. }}.bind(this)
  1043. });
  1044. },
  1045. selected: function(){
  1046. if (this.view.currentSelectedModule){
  1047. if (this.view.currentSelectedModule==this){
  1048. return true;
  1049. }else{
  1050. this.view.currentSelectedModule.unSelected();
  1051. }
  1052. }
  1053. this.node.setStyles(this.css.viewCalculateFieldNode_selected);
  1054. // new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1055. try {
  1056. this.node.scrollIntoView(false);
  1057. }catch (e) {
  1058. }
  1059. this.view.currentSelectedModule = this;
  1060. this.isSelected = true;
  1061. this._showActions();
  1062. this.showProperty();
  1063. },
  1064. unSelected: function(){
  1065. this.view.currentSelectedModule = null;
  1066. //this.node.setStyles(this.css.viewTitleColumnNode);
  1067. // if (this.isError){
  1068. // this.node.setStyles(this.css.viewTitleColumnNode_error)
  1069. // }else{
  1070. this.node.setStyles(this.css.viewCalculateFieldNode)
  1071. // }
  1072. // this.listNode.setStyles(this.css.cloumnListNode);
  1073. this.isSelected = false;
  1074. this._hideActions();
  1075. this.hideProperty();
  1076. },
  1077. _createIconAction: function(){
  1078. if (!this.actionArea){
  1079. this.actionArea = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.view.areaNode, "after");
  1080. this._createAction({
  1081. "name": "move",
  1082. "icon": "move1.png",
  1083. "event": "mousedown",
  1084. "action": "move",
  1085. "title": MWF.APPDIPD.LP.action.move
  1086. });
  1087. this._createAction({
  1088. "name": "add",
  1089. "icon": "add.png",
  1090. "event": "click",
  1091. "action": "addColumn",
  1092. "title": MWF.APPDIPD.LP.action.add
  1093. });
  1094. this._createAction({
  1095. "name": "delete",
  1096. "icon": "delete1.png",
  1097. "event": "click",
  1098. "action": "delete",
  1099. "title": MWF.APPDIPD.LP.action["delete"]
  1100. });
  1101. }
  1102. },
  1103. _createAction: function(action){
  1104. var actionNode = new Element("div", {
  1105. "styles": this.css.actionNodeStyles,
  1106. "title": action.title
  1107. }).inject(this.actionArea);
  1108. actionNode.setStyle("background", "url("+this.view.path+this.view.options.style+"/action/"+action.icon+") no-repeat left center");
  1109. actionNode.addEvent(action.event, function(e){
  1110. this[action.action](e);
  1111. }.bind(this));
  1112. actionNode.addEvents({
  1113. "mouseover": function(e){
  1114. e.target.setStyle("border", "1px solid #999");
  1115. }.bind(this),
  1116. "mouseout": function(e){
  1117. e.target.setStyle("border", "1px solid #F1F1F1");
  1118. }.bind(this)
  1119. });
  1120. },
  1121. _setActionAreaPosition: function(){
  1122. var p = this.node.getPosition(this.view.areaNode.getOffsetParent());
  1123. var y = p.y-25;
  1124. var x = p.x;
  1125. this.actionArea.setPosition({"x": x, "y": y});
  1126. },
  1127. _showActions: function(){
  1128. if (this.actionArea){
  1129. this._setActionAreaPosition();
  1130. this.actionArea.setStyle("display", "block");
  1131. }
  1132. },
  1133. _hideActions: function(){
  1134. if (this.actionArea) this.actionArea.setStyle("display", "none");
  1135. },
  1136. showProperty: function(){
  1137. if (!this.property){
  1138. this.property = new MWF.xApplication.query.ImporterDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  1139. "path": this.propertyPath,
  1140. "onPostLoad": function(){
  1141. this.property.show();
  1142. var processDiv = this.property.propertyContent.getElements("#"+this.json.id+"dataPathSelectedProcessArea");
  1143. var cmsDiv = this.property.propertyContent.getElements("#"+this.json.id+"dataPathSelectedCMSArea");
  1144. if (this.view.json.type=="cms"){
  1145. processDiv.setStyle("display", "none");
  1146. cmsDiv.setStyle("display", "block");
  1147. }else{
  1148. processDiv.setStyle("display", "block");
  1149. cmsDiv.setStyle("display", "none");
  1150. }
  1151. }.bind(this)
  1152. });
  1153. this.property.load();
  1154. }else{
  1155. this.property.show();
  1156. }
  1157. },
  1158. "delete": function(e){
  1159. var _self = this;
  1160. if (!e) e = this.node;
  1161. this.view.designer.confirm("warn", e, MWF.APPDIPD.LP.notice.deleteFieldTitle, MWF.APPDIPD.LP.notice.deleteField, 300, 120, function(){
  1162. _self.destroy();
  1163. this.close();
  1164. }, function(){
  1165. this.close();
  1166. }, null);
  1167. },
  1168. // setEditStyle: function(name, input, oldValue){
  1169. // debugger;
  1170. // if (name=="displayName") this.resetTextNode();
  1171. // if (name=="selectType") this.resetTextNode();
  1172. // if (name=="attribute") this.resetTextNode();
  1173. // if (name=="path") this.resetTextNode();
  1174. // },
  1175. _setEditStyle_custom: function(name, input, oldValue){
  1176. //calculate
  1177. debugger;
  1178. if (name=="displayName"){
  1179. this.resetTextNode();
  1180. this.view.property.loadSelectField();
  1181. }
  1182. if (name=="selectType") this.resetTextNode();
  1183. if (name=="attribute") this.resetTextNode();
  1184. if (name=="path"){
  1185. this.resetTextNode();
  1186. this.view.property.loadSelectField();
  1187. }
  1188. // if (["isTitle","isSummary","isPublisher","isProcessTitle","isProcessDrafter"].contains(name)){
  1189. // this.view.checkUniqueSetting(this, name, input.get("value"));
  1190. // }
  1191. },
  1192. resetTextNode: function( index ){
  1193. // var listText = (this.json.selectType=="attribute") ? (this.json.attribute || "") : (this.json.path || "");
  1194. // if (!listText) listText = "unnamed";
  1195. // var colName = this.index2ColumnName( index || this.index );
  1196. // colName = colName ? ( colName + ": " ) : "";
  1197. var displayName;
  1198. if( this.json.path && (!this.json.displayName || this.json.displayName === this.view.designer.lp.unnamed) ){
  1199. displayName = this.json.path;
  1200. }else{
  1201. displayName = this.json.displayName
  1202. }
  1203. this.textNode.set("text", displayName );
  1204. },
  1205. destroy: function(){
  1206. if (this.view.currentSelectedModule==this) this.view.currentSelectedModule = null;
  1207. if (this.actionArea) this.actionArea.destroy();
  1208. // if (this.listNode) this.listNode.destroy();
  1209. if (this.property) this.property.propertyContent.destroy();
  1210. var idx = this.view.calculateItems.indexOf(this);
  1211. if (this.view.json.data.calculateFieldList) this.view.json.data.calculateFieldList.erase(this.json);
  1212. // if (this.view.json.data.calculate) if (this.view.json.data.calculate.calculateList) this.view.json.data.calculate.calculateList.erase(this.json);
  1213. this.view.calculateItems.erase(this);
  1214. if (this.view.property) this.view.property.loadStatColumnSelect();
  1215. this.areaNode.destroy();
  1216. this.view.property.loadSelectField();
  1217. this.view.selected();
  1218. // this.view.setViewWidth();
  1219. MWF.release(this);
  1220. delete this;
  1221. },
  1222. addColumn: function(e, data){
  1223. MWF.require("MWF.widget.UUID", function(){
  1224. var json;
  1225. if (data){
  1226. json = Object.clone(data);
  1227. json.id = (new MWF.widget.UUID).id;
  1228. json.column = (new MWF.widget.UUID).id;
  1229. }else{
  1230. var id = (new MWF.widget.UUID).id;
  1231. json = {
  1232. "id": id,
  1233. "column": id,
  1234. "displayName": this.view.designer.lp.unnamed,
  1235. "orderType": "original"
  1236. };
  1237. }
  1238. var idx = this.view.json.data.calculateFieldList.indexOf(this.json);
  1239. this.view.json.data.calculateFieldList.splice(idx, 0, json);
  1240. var column = new MWF.xApplication.query.ImporterDesigner.Importer.CalculateField(json, this.view, this);
  1241. this.view.calculateItems.splice(idx, 0, column);
  1242. column.selected();
  1243. }.bind(this));
  1244. },
  1245. move: function(e){
  1246. var columnNodes = [];
  1247. this.view.calculateItems.each(function(item){
  1248. if (item!=this){
  1249. columnNodes.push(item.areaNode);
  1250. }
  1251. }.bind(this));
  1252. this._createMoveNode();
  1253. this._setNodeMove(columnNodes, e);
  1254. },
  1255. _createMoveNode: function(){
  1256. this.moveNode = new Element("div", {"text": this.node.get("text")});
  1257. this.moveNode.inject(this.view.designer.content);
  1258. this.moveNode.setStyles({
  1259. "border": "2px dashed #ffa200",
  1260. "opacity": 0.7,
  1261. "height": "30px",
  1262. "line-height": "30px",
  1263. "padding": "0px 10px",
  1264. "position": "absolute"
  1265. });
  1266. },
  1267. _setMoveNodePosition: function(e){
  1268. var x = e.page.x+2;
  1269. var y = e.page.y+2;
  1270. this.moveNode.positionTo(x, y);
  1271. },
  1272. createMoveFlagNode: function(){
  1273. this.moveFlagNode = new Element("td", {"styles": this.css.moveFieldFlagNode});
  1274. },
  1275. _setNodeMove: function(droppables, e){
  1276. this._setMoveNodePosition(e);
  1277. var movePosition = this.moveNode.getPosition();
  1278. var moveSize = this.moveNode.getSize();
  1279. var contentPosition = this.content.getPosition();
  1280. var contentSize = this.content.getSize();
  1281. var nodeDrag = new Drag.Move(this.moveNode, {
  1282. "droppables": droppables,
  1283. "limit": {
  1284. "x": [contentPosition.x, contentPosition.x+contentSize.x],
  1285. "y": [movePosition.y, movePosition.y+moveSize.y]
  1286. },
  1287. "onEnter": function(dragging, inObj){
  1288. if (!this.moveFlagNode) this.createMoveFlagNode();
  1289. this.moveFlagNode.inject(inObj, "before");
  1290. }.bind(this),
  1291. "onLeave": function(dragging, inObj){
  1292. if (this.moveFlagNode){
  1293. this.moveFlagNode.dispose();
  1294. }
  1295. }.bind(this),
  1296. "onDrop": function(dragging, inObj){
  1297. if (inObj){
  1298. this.areaNode.inject(inObj, "before");
  1299. var column = inObj.retrieve("column");
  1300. // this.listNode.inject(column.listNode, "before");
  1301. this.view.json.data.calculateFieldList.erase(this.json);
  1302. this.view.calculateItems.erase(this);
  1303. var idx = this.view.json.data.calculateFieldList.indexOf(column.json);
  1304. this.view.json.data.calculateFieldList.splice(idx, 0, this.json);
  1305. this.view.calculateItems.splice(idx, 0, this);
  1306. if (this.moveNode) this.moveNode.destroy();
  1307. if (this.moveFlagNode) this.moveFlagNode.destroy();
  1308. this._setActionAreaPosition();
  1309. // this.view.items.each( function (item, i) {
  1310. // item.resetIndex(i);
  1311. // });
  1312. }else{
  1313. if (this.moveNode) this.moveNode.destroy();
  1314. if (this.moveFlagNode) this.moveFlagNode.destroy();
  1315. }
  1316. }.bind(this),
  1317. "onCancel": function(dragging){
  1318. if (this.moveNode) this.moveNode.destroy();
  1319. if (this.moveFlagNode) this.moveFlagNode.destroy();
  1320. }.bind(this)
  1321. });
  1322. nodeDrag.start(e);
  1323. }
  1324. })