Main.js 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. MWF.xApplication.cms = MWF.xApplication.cms || {};
  2. //MWF.xApplication.cms.Column = MWF.xApplication.cms.Column || {};
  3. //MWF.xDesktop.requireApp("cms.ColumnManager", "Actions.RestActions", null, false);
  4. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  5. MWF.xApplication.cms.Column.Main = new Class({
  6. Extends: MWF.xApplication.Common.Main,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default",
  10. "name": "cms.Column",
  11. "icon": "icon.png",
  12. "width": "1000",
  13. "height": "600",
  14. "isResize": true,
  15. "isMax": true,
  16. "title": MWF.xApplication.cms.Column.LP.title
  17. },
  18. onQueryLoad: function () {
  19. this.lp = MWF.xApplication.cms.Column.LP;
  20. this.defaultColumnIcon = "../x_component_cms_Column/$Main/" + this.options.style + "/icon/column.png";
  21. this.defaultCategoryIcon = "../x_component_cms_Column/$Main/" + this.options.style + "/icon/category2.png";
  22. },
  23. loadApplication: function (callback) {
  24. this.isAdmin = MWF.AC.isCMSManager();
  25. if (!this.restActions) this.restActions = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.ColumnManager.Actions.RestActions();
  26. this.columns = [];
  27. this.categorys = [];
  28. this.deleteElements = [];
  29. this.createNode();
  30. this.loadApplicationContent();
  31. if (callback) callback();
  32. },
  33. createNode: function () {
  34. this.content.setStyle("overflow", "hidden");
  35. this.node = new Element("div", {
  36. "styles": this.css.container
  37. }).inject(this.content);
  38. this.node.loadCss("../x_component_cms_Column/$Main/"+ this.options.style +"/style.css");
  39. },
  40. reload: function(appType, callback){
  41. // if( appType ){
  42. this.reloadTop(appType, callback);
  43. // }else{
  44. // this.reloadTop();
  45. // this.columnContentAreaNode.empty();
  46. // this.createColumnNodes(callback);
  47. // }
  48. },
  49. loadApplicationContent: function () {
  50. //this.columnAreaNode = new Element("div", {
  51. // "styles": this.css.columnAreaNode
  52. //}).inject(this.node);
  53. this.loadTopNode();
  54. //this.setColumnAreaSize();
  55. //this.addEvent("resize", this.setColumnAreaSize);
  56. this.loadColumnContentArea();
  57. this.setCurrentAppType( "all", this.columnAllTypeNode );
  58. //this.setColumnContentSize();
  59. this.setContentSize();
  60. this.addEvent("resize", function(){
  61. this.setContentSize();
  62. }.bind(this));
  63. },
  64. reloadTop : function( appType, callback, noRefreshContent ){
  65. this.columnToolbarAreaNode.empty();
  66. if( !appType )appType = this.currentAppType;
  67. this.currentAppType = null;
  68. this.currentAppTypeNode = null;
  69. this.loadTopNode( appType, callback, noRefreshContent );
  70. },
  71. loadTopNode: function( appType, callback, noRefreshContent ){
  72. if( !this.columnToolbarAreaNode ){
  73. this.columnToolbarAreaNode = new Element("div.columnToolbarAreaNode", {
  74. "styles": this.css.columnToolbarAreaNode
  75. }).inject(this.node);
  76. }
  77. this.columnAllTypeNode = new Element("div.columnTop_All",{
  78. "styles" : this.css.columnTop_All,
  79. "text" : this.lp.allApp
  80. }).inject( this.columnToolbarAreaNode );
  81. this.columnAllTypeNode.addEvents({
  82. "mouseover" : function(){
  83. if( this.currentAppTypeNode !== this.columnAllTypeNode )this.columnAllTypeNode.setStyles( this.css.columnTop_All_over );
  84. }.bind(this),
  85. "mouseout" : function(){
  86. if( this.currentAppTypeNode !== this.columnAllTypeNode )this.columnAllTypeNode.setStyles( this.css.columnTop_All );
  87. }.bind(this),
  88. "click": function () {
  89. this.setCurrentAppType( "all", this.columnAllTypeNode );
  90. }.bind(this)
  91. });
  92. if( appType && appType === "all" ){
  93. this.setCurrentAppType( "all", this.columnAllTypeNode, callback, noRefreshContent );
  94. }
  95. if (MWF.AC.isCMSCreator()) {
  96. this.createColumnNode = new Element("div.createColumnNode", {
  97. "styles": this.css.createColumnNode,
  98. "text": this.lp.column.create
  99. }).addClass("o2_cms_column_createColumnNode").inject(this.columnToolbarAreaNode);
  100. this.createColumnNode.addEvents({
  101. "mouseover" : function(){
  102. this.createColumnNode.setStyles( this.css.createColumnNode_over );
  103. }.bind(this),
  104. "mouseout" : function(){
  105. this.createColumnNode.setStyles( this.css.createColumnNode );
  106. }.bind(this),
  107. "click": function () {
  108. this.createColumn();
  109. }.bind(this)
  110. });
  111. this.searchNode = new Element("div.searchNode", {
  112. "styles": this.css.columnTop_search
  113. }).inject(this.columnToolbarAreaNode);
  114. this.searchInput = new Element("input.searchInput", {
  115. "styles": this.css.columnTop_searchInput,
  116. "placeholder": this.lp.searchAppPlacholder
  117. }).inject(this.searchNode);
  118. this.searchButton = new Element("i.o2icon-search", {
  119. "styles": this.css.columnTop_searchButton
  120. }).inject(this.searchNode);
  121. this.searchInput.addEvents({
  122. focus: function(){
  123. this.searchNode.addClass("mainColor_border");
  124. this.searchButton.addClass("mainColor_color");
  125. }.bind(this),
  126. blur: function () {
  127. this.searchNode.removeClass("mainColor_border");
  128. this.searchButton.removeClass("mainColor_color");
  129. }.bind(this),
  130. keydown: function (e) {
  131. if( (e.keyCode || e.code) === 13 ){
  132. this.searchApp();
  133. }
  134. }.bind(this)
  135. });
  136. this.searchButton.addEvent("click", function (e) {
  137. this.searchApp();
  138. }.bind(this));
  139. this.findNode = new Element("div.createColumnNode", {
  140. "styles": this.css.findNode,
  141. "text": this.lp.column.findDesigner
  142. }).inject(this.columnToolbarAreaNode);
  143. this.findNode.addEvent("click", function(){
  144. var options = {
  145. "filter": {
  146. "moduleList": ["cms"]
  147. }
  148. };
  149. layout.openApplication(null, "FindDesigner", options);
  150. }.bind(this));
  151. }
  152. this.columnTypeListContaienr = new Element("div.columnTop_category", {
  153. "styles": this.css.columnTop_category
  154. }).inject(this.columnToolbarAreaNode);
  155. this.loadAppType( appType, callback, noRefreshContent );
  156. //this.columnToolbarTextNode = new Element("div.columnToolbarTextNode", {
  157. // "styles": this.css.columnToolbarTextNode,
  158. // "text": this.lp.column.title
  159. //}).inject(this.columnToolbarAreaNode);
  160. },
  161. searchApp: function(){
  162. var key = this.searchInput && this.searchInput.get("value");
  163. this.columns.each(function (app) {
  164. if( !key || app.titleNode.get("text").contains( key )){
  165. app.node.show();
  166. }else{
  167. app.node.hide();
  168. }
  169. }.bind(this));
  170. },
  171. loadAppType : function( appType, callback, noRefreshContent ){
  172. var _self = this;
  173. debugger;
  174. this.restActions.listAllAppTypeByManager( function( json ){
  175. (json.data || []).each( function( typeObject ){
  176. var cNode = new Element( "div.columnTop_category", {
  177. "styles" : this.css.columnTop_categoryItem,
  178. "text" : typeObject.appType + "(" + typeObject.count + ")",
  179. "events" : {
  180. "mouseover" : function( ev ){
  181. if( this.currentAppTypeNode !== ev.target )ev.target.setStyles( this.css.columnTop_categoryItem_over );
  182. }.bind(this),
  183. "mouseout" : function( ev ){
  184. if( this.currentAppTypeNode !== ev.target )ev.target.setStyles( this.css.columnTop_categoryItem );
  185. }.bind(this),
  186. "click": function ( ev ) {
  187. _self.setCurrentAppType( this, ev.target );
  188. }.bind( typeObject.appType )
  189. }
  190. }).inject( this.columnTypeListContaienr )
  191. if( appType && appType === typeObject.appType ){
  192. _self.setCurrentAppType( this, cNode, callback, noRefreshContent );
  193. }
  194. }.bind(this))
  195. if (this.columnTypeListContaienr.getScrollSize().y>this.columnTypeListContaienr.getSize().y) this.createTypeExpandButton();
  196. }.bind(this))
  197. },
  198. createTypeExpandButton : function(){
  199. this.columnTypeExpandNode = new Element("div.columnTop_categoryExpandButton",{
  200. "styles" : this.css.columnTop_categoryExpandButton
  201. }).inject( this.columnTypeListContaienr, "before" );
  202. this.columnTypeExpandNode.addEvent("click", this.expandOrCollapseCategory.bind(this));
  203. },
  204. expandOrCollapseCategory : function(e){
  205. if (!this.categoryMorph) this.categoryMorph = new Fx.Morph(this.columnTypeListContaienr, {"duration": 100});
  206. if( !this.expand ){
  207. this.columnTypeListContaienr.setStyles( this.css.columnTop_category_more );
  208. this.categoryMorph.start({"height": ""+this.columnTypeListContaienr.getScrollSize().y+"px"});
  209. this.expandOrCollapseCategoryFun = this.expandOrCollapseCategory.bind(this);
  210. this.content.addEvent("click", this.expandOrCollapseCategoryFun);
  211. this.expand = true;
  212. }else{
  213. this.columnTypeListContaienr.setStyles( this.css.columnTop_category );
  214. this.categoryMorph.start({"height": ""+this.columnToolbarAreaNode.getSize().y+"px"});
  215. if (this.expandOrCollapseCategoryFun) this.content.removeEvent("click", this.expandOrCollapseCategoryFun);
  216. this.expand = false;
  217. }
  218. e.stopPropagation();
  219. },
  220. setCurrentAppType : function( appType, target, callback, noRefreshContent ){
  221. if( this.currentAppType ){
  222. if( this.currentAppType === "all" ){
  223. this.currentAppTypeNode.setStyles( this.css.columnTop_All );
  224. this.currentAppTypeNode.removeClass("o2_cms_column_all_current");
  225. }else{
  226. this.currentAppTypeNode.setStyles( this.css.columnTop_categoryItem );
  227. this.currentAppTypeNode.removeClass("o2_cms_column_categoryItem_current");
  228. }
  229. }
  230. if( appType === "all" ){
  231. target.setStyles( this.css.columnTop_All_current );
  232. target.addClass("o2_cms_column_all_current");
  233. }else{
  234. target.setStyles( this.css.columnTop_categoryItem_current );
  235. target.addClass("o2_cms_column_categoryItem_current");
  236. }
  237. this.currentAppType = appType;
  238. this.currentAppTypeNode = target;
  239. if(!noRefreshContent){
  240. this.createColumnNodes( callback );
  241. }
  242. },
  243. setContentSize: function(){
  244. var nodeSize = this.node.getSize();
  245. var titlebarSize = this.columnToolbarAreaNode ? this.columnToolbarAreaNode.getSize() : {"x":0,"y":0};
  246. this.scrollNode.setStyle("height", ""+(nodeSize.y-titlebarSize.y)+"px");
  247. if (this.contentWarpNode){
  248. var count = (nodeSize.x/287).toInt();
  249. var x = 287 * count;
  250. var m = (nodeSize.x-x)/2-10;
  251. this.contentWarpNode.setStyles({
  252. "width": ""+x+"px",
  253. "margin-left": ""+m+"px"
  254. });
  255. //this.titleBar.setStyles({
  256. // "margin-left": ""+(m+10)+"px",
  257. // "margin-right": ""+(m+10)+"px"
  258. //})
  259. }
  260. if( this.columnTypeListContaienr ){
  261. if ( this.columnTypeListContaienr.getScrollSize().y> Math.round(this.columnTypeListContaienr.getSize().y)) {
  262. if( !this.columnTypeExpandNode ){
  263. this.createTypeExpandButton();
  264. }else{
  265. this.columnTypeExpandNode.setStyle("display","")
  266. }
  267. }else{
  268. if(this.columnTypeExpandNode)this.columnTypeExpandNode.setStyle("display","none");
  269. }
  270. }
  271. },
  272. //setColumnAreaSize: function () {
  273. // var nodeSize = this.node.getSize();
  274. // var toolbarSize = this.columnToolbarAreaNode.getSize();
  275. // var y = nodeSize.y - toolbarSize.y;
  276. //
  277. // this.columnAreaNode.setStyle("height", "" + y + "px");
  278. //
  279. // if (this.columnContentAreaNode) {
  280. // var count = (nodeSize.x / 282).toInt();
  281. // var x = 282 * count;
  282. // var m = (nodeSize.x - x) / 2 - 10;
  283. // this.columnContentAreaNode.setStyles({
  284. // //"width": ""+x+"px",
  285. // "margin-left": "" + m + "px"
  286. // });
  287. // }
  288. //},
  289. //setColumnContentSize: function () {
  290. // var nodeSize = this.node.getSize();
  291. // if (this.columnContentAreaNode) {
  292. // var count = (nodeSize.x / 282).toInt();
  293. // var x = 282 * count;
  294. // var m = (nodeSize.x - x) / 2 - 10;
  295. // this.columnContentAreaNode.setStyles({
  296. // //"width": ""+x+"px",
  297. // "margin-left": "" + m + "px"
  298. // });
  299. // }
  300. //},
  301. loadColumnContentArea: function () {
  302. this.scrollNode = new Element("div", {
  303. "styles": this.css.scrollNode
  304. }).inject(this.node);
  305. this.contentWarpNode = new Element("div", {
  306. "styles": this.css.contentWarpNode
  307. }).inject(this.scrollNode);
  308. this.contentContainerNode = new Element("div",{
  309. "styles" : this.css.contentContainerNode
  310. }).inject(this.contentWarpNode);
  311. this.columnContentAreaNode = new Element("div", {
  312. "styles": this.css.columnContentAreaNode
  313. }).inject(this.contentContainerNode);
  314. //this.loadController(function () {
  315. //}.bind(this));
  316. //MWF.require("MWF.widget.DragScroll", function(){
  317. // new MWF.widget.DragScroll(this.columnContentAreaNode);
  318. //}.bind(this));
  319. //MWF.require("MWF.widget.ScrollBar", function () {
  320. // new MWF.widget.ScrollBar(this.columnContentAreaNode);
  321. //}.bind(this));
  322. },
  323. //loadController: function (callback) {
  324. //this.availableApp = [];
  325. //this.restActions.listAppByManager( function( json ){
  326. // (json.data||[]).each(function (d) {
  327. // this.availableApp.push(d.id);
  328. // }.bind(this));
  329. // if (callback)callback();
  330. //}.bind(this), null, true );
  331. //this.restActions.listControllerByPerson(layout.desktop.session.user.distinguishedName, function (json) {
  332. // if (json && json.data && json.data.length) {
  333. // json.data.each(function (d) {
  334. // this.availableApp.push(d.objectId);
  335. // }.bind(this))
  336. // }
  337. // if (callback)callback();
  338. //}.bind(this), null, true)
  339. //},
  340. //hasPermision: function (appId) {
  341. // return this.isAdmin || this.availableApp.contains(appId);
  342. //},
  343. createColumnNodes: function ( callback ) {
  344. this.columnContentAreaNode.empty();
  345. if( this.currentAppType === "all" ){
  346. this.restActions.listAppByManager(function (json){
  347. this._createColumnNodes( json );
  348. if(callback)callback();
  349. }.bind(this));
  350. }else{
  351. this.restActions.listWhatICanManageWithAppType(this.currentAppType, function (json){
  352. this._createColumnNodes( json );
  353. if(callback)callback();
  354. }.bind(this))
  355. }
  356. },
  357. _createColumnNodes : function( json ){
  358. var emptyColumn = null;
  359. if (json && json.data && json.data.length) {
  360. var tmpArr = json.data;
  361. tmpArr.sort(function(a , b ){
  362. return parseFloat( a.appInfoSeq ) - parseFloat(b.appInfoSeq);
  363. });
  364. json.data = tmpArr;
  365. json.data.each(function (column, index) {
  366. ///if (this.hasPermision(column.id)) {
  367. this.index = index;
  368. var column = new MWF.xApplication.cms.Column.Column(this, column, {index : index});
  369. column.load();
  370. this.columns.push(column);
  371. //}
  372. }.bind(this));
  373. }
  374. if (this.columns.length == 0) {
  375. this.noElementNode = new Element("div", {
  376. "styles": this.css.noElementNode,
  377. "text": this.lp.column.noElement
  378. }).inject(this.columnContentAreaNode);
  379. }
  380. },
  381. createColumn: function () {
  382. //var column = new MWF.xApplication.cms.Column.Column(this, null, { index: ++this.index });
  383. //column.createColumn(this.node);
  384. var form = new MWF.xApplication.cms.Column.PopupForm(this, {}, {
  385. title : this.lp.column.create
  386. }, {
  387. app : this,
  388. container : this.content,
  389. lp : this.lp.column,
  390. css : {},
  391. actions : this.restActions
  392. });
  393. form.create();
  394. }
  395. /*
  396. createLoadding: function(){
  397. this.loaddingNode = new Element("div", {
  398. "styles": this.css.noApplicationNode,
  399. "text": this.lp.loadding
  400. }).inject(this.applicationContentNode);
  401. },
  402. removeLoadding: function(){
  403. if (this.loaddingNode) this.loaddingNode.destroy();
  404. },
  405. */
  406. });
  407. MWF.xApplication.cms.Column.Column = new Class({
  408. Implements: [Options, Events],
  409. options: {
  410. "where": "bottom",
  411. "index" : 1
  412. },
  413. initialize: function (app, data, options) {
  414. this.setOptions(options);
  415. this.app = app;
  416. this.container = this.app.columnContentAreaNode;
  417. this.data = data;
  418. this.isNew = false;
  419. this.lp = this.app.lp.column;
  420. },
  421. load: function () {
  422. this.data.name = this.data.appName;
  423. var columnName = this.data.appName;
  424. var alias = this.data.appAlias;
  425. var memo = this.data.description;
  426. var order = this.data.appInfoSeq;
  427. var creator = this.data.creatorUid;
  428. var createTime = this.data.createTime;
  429. //var icon = this.data.appIcon;
  430. //if( !icon || icon == "")icon = this.app.defaultColumnIcon;
  431. var itemNode = this.node = new Element("div.columnItem", {
  432. "styles": this.app.css.columnItemNode
  433. }).inject(this.container, this.options.where);
  434. itemNode.store("columnName", columnName);
  435. //itemNode.setStyle("background-color", this.options.bgColor[(Math.random()*10).toInt()]);
  436. var topNode = new Element("div", {
  437. "styles": this.app.css.columnItemTopNode
  438. }).inject(itemNode);
  439. if( this.data.iconColor ){
  440. topNode.setStyle("background-color" , "rgba("+ this.data.iconColor +",1)" )
  441. }
  442. var titleNode = new Element("div", {
  443. "styles": this.app.css.columnItemTitleNode,
  444. "text": columnName,
  445. "title": (alias) ? columnName + " (" + alias + ") " : columnName
  446. }).inject(topNode);
  447. this.titleNode = titleNode;
  448. var iconAreaNode = new Element("div",{
  449. "styles": this.app.css.columnItemIconAreaNode
  450. }).inject(itemNode);
  451. if( this.data.iconColor ){
  452. iconAreaNode.setStyle("border-color" , "rgba("+ this.data.iconColor +",1)" )
  453. }
  454. var iconNode = this.iconNode = new Element("div", {
  455. "styles": this.app.css.columnItemIconNode
  456. }).inject(itemNode);
  457. //iconNode.setStyles({
  458. // "background-image" : "url("+icon+")"
  459. //});
  460. if (this.data.appIcon) {
  461. this.iconNode.setStyle("background-image", "url(data:image/png;base64," + this.data.appIcon + ")");
  462. } else {
  463. this.iconNode.setStyle("background-image", "url(" + this.app.defaultColumnIcon + ")");
  464. }
  465. this.iconNode.makeLnk({
  466. "par": this._getLnkPar()
  467. });
  468. var middleNode = new Element("div", {
  469. "styles": this.app.css.columnItemMiddleNode
  470. }).inject(itemNode);
  471. var description = ( memo && memo != "") ? memo : this.lp.noDescription;
  472. var descriptionNode = new Element("div", {
  473. "styles": this.app.css.columnItemDescriptionNode,
  474. "text": description,
  475. "title": description
  476. }).inject(middleNode);
  477. var _self = this;
  478. itemNode.addEvents({
  479. "mouseover": function () {
  480. if (!_self.selected){
  481. this.setStyles(_self.app.css.columnItemNode_over);
  482. this.addClass("o2_cms_column_columnNode_over");
  483. }
  484. },
  485. "mouseout": function () {
  486. if (!_self.selected){
  487. this.setStyles(_self.app.css.columnItemNode);
  488. this.removeClass("o2_cms_column_columnNode_over");
  489. }
  490. },
  491. "click": function (e) {
  492. _self.clickColumnNode(_self, this, e)
  493. }
  494. });
  495. var bottomNode = new Element("div", {
  496. "styles": this.app.css.columnItemBottomNode
  497. }).inject(itemNode);
  498. var bottomTitleNode = new Element("div", {
  499. "styles": this.app.css.columnItemCategoryTitleNode,
  500. "text" : this.lp.category
  501. }).inject(bottomNode);
  502. var bottomContentNode_category = new Element("div", {
  503. "styles": this.app.css.columnItemCategoryContentNode
  504. }).inject(bottomNode);
  505. this.app.restActions.listCategory( this.data.id, function ( json ) {
  506. var data = json.data || [];
  507. data.each( function( category ){
  508. var bottomItemNode = new Element("div",{
  509. styles : this.app.css.columnItemBottomItemNode,
  510. text : category.name
  511. }).inject(bottomContentNode_category);
  512. bottomItemNode.addEvents( {
  513. "click": function( ev ){
  514. this.obj.clickColumnNode(this.obj, ev.target, ev, this.data.id);
  515. ev.stopPropagation();
  516. }.bind({ obj : this, data : category }),
  517. "mouseover" : function(){
  518. this.node.setStyles( this.obj.app.css.columnItemBottomItemNode_over );
  519. }.bind({ obj : this, node : bottomItemNode }),
  520. "mouseout" : function(){
  521. this.node.setStyles( this.obj.app.css.columnItemBottomItemNode );
  522. }.bind({ obj : this, node : bottomItemNode })
  523. })
  524. }.bind(this))
  525. }.bind(this) );
  526. var bottomTitleNode = new Element("div", {
  527. "styles": this.app.css.columnItemFormTitleNode,
  528. "text" : this.lp.form
  529. }).inject(bottomNode);
  530. var bottomContentNode_form = new Element("div", {
  531. "styles": this.app.css.columnItemFormContentNode
  532. }).inject(bottomNode);
  533. this.app.restActions.listForm( this.data.id, function ( json ) {
  534. var data = json.data || [];
  535. data.each( function( form ){
  536. var bottomItemNode = new Element("div",{
  537. styles : this.app.css.columnItemBottomItemNode,
  538. text : form.name
  539. }).inject(bottomContentNode_form);
  540. bottomItemNode.addEvents( {
  541. "click": function( ev ){
  542. this.obj.openForm( this.data );
  543. ev.stopPropagation();
  544. }.bind({ obj : this, data : form }),
  545. "mouseover" : function(){
  546. this.node.setStyles( this.obj.app.css.columnItemBottomItemNode_over );
  547. }.bind({ obj : this, node : bottomItemNode }),
  548. "mouseout" : function(){
  549. this.node.setStyles( this.obj.app.css.columnItemBottomItemNode );
  550. }.bind({ obj : this, node : bottomItemNode })
  551. })
  552. }.bind(this))
  553. }.bind(this) );
  554. if ((creator == layout.desktop.session.user.distinguishedName) || MWF.AC.isCMSManager()) {
  555. this.delAdctionNode = new Element("div.delNode", {
  556. "styles": this.app.css.columnItemDelActionNode,
  557. "title": this.lp["delete"]
  558. }).inject(itemNode);
  559. itemNode.addEvents({
  560. "mouseover": function () {
  561. this.delAdctionNode.setStyle("display","");
  562. }.bind(this),
  563. "mouseout": function () {
  564. this.delAdctionNode.setStyle("display","none");
  565. }.bind(this)
  566. });
  567. this.delAdctionNode.addEvent("click", function (e) {
  568. this.deleteColumn(e);
  569. e.stopPropagation();
  570. }.bind(this));
  571. }
  572. if ((creator == layout.desktop.session.user.distinguishedName) || MWF.AC.isCMSManager()) {
  573. this.editAdctionNode = new Element("div.editNode", {
  574. "styles": this.app.css.columnItemEditActionNode,
  575. "title": this.lp.edit
  576. }).inject(itemNode);
  577. itemNode.addEvents({
  578. "mouseover": function () {
  579. this.editAdctionNode.setStyle("display","");
  580. }.bind(this),
  581. "mouseout": function () {
  582. this.editAdctionNode.setStyle("display","none");
  583. }.bind(this)
  584. });
  585. this.editAdctionNode.addEvent("click", function (e) {
  586. this.edit(e);
  587. e.stopPropagation();
  588. }.bind(this));
  589. }
  590. //if ((creator == layout.desktop.session.user.distinguishedName) || MWF.AC.isCMSManager()) {
  591. // this.exportAdctionNode = new Element("div.exportNode", {
  592. // "styles": this.app.css.columnItemExportActionNode,
  593. // "title": this.lp.export
  594. // }).inject(itemNode);
  595. //
  596. // itemNode.addEvents({
  597. // "mouseover": function () {
  598. // this.exportAdctionNode.setStyle("display","");
  599. // }.bind(this),
  600. // "mouseout": function () {
  601. // this.exportAdctionNode.setStyle("display","none");
  602. // }.bind(this)
  603. // });
  604. // this.exportAdctionNode.addEvent("click", function (e) {
  605. // this.export(e);
  606. // e.stopPropagation();
  607. // }.bind(this));
  608. //}
  609. },
  610. _getLnkPar: function(){
  611. var lnkIcon = this.app.defaultColumnIcon;
  612. if (this.data.icon) lnkIcon = "data:image/png;base64," + this.data.appIcon;
  613. var appId = "cms.ColumnManager"+this.data.id;
  614. return {
  615. "icon": lnkIcon,
  616. "title": this.data.appName,
  617. "par": "cms.ColumnManager#{\"column\": \""+this.data.id+"\", \"appId\": \""+appId+"\"}"
  618. };
  619. },
  620. export: function(){
  621. //var applicationjson = {
  622. // "application": {},
  623. // "processList": [],
  624. // "formList": [],
  625. // "dictionaryList": [],
  626. // "scriptList": []
  627. //};
  628. //this.app.restActions.getApplication(this.data.name, function(json){
  629. //
  630. //}
  631. MWF.xDesktop.requireApp("cms.Column", "Exporter", function(){
  632. (new MWF.xApplication.cms.Column.Exporter(this.app, this.data)).load();
  633. }.bind(this));
  634. },
  635. edit : function(){
  636. var form = new MWF.xApplication.cms.Column.PopupForm(this.app, this.data, {
  637. title : this.lp.edit
  638. }, {
  639. app : this.app,
  640. container : this.app.content,
  641. lp : this.lp,
  642. css : {},
  643. actions : this.app.restActions
  644. });
  645. form.edit();
  646. },
  647. openForm: function( form ){
  648. layout.desktop.getFormDesignerStyle(function(){
  649. var _self = this;
  650. var options = {
  651. "style": layout.desktop.formDesignerStyle,
  652. "onQueryLoad": function(){
  653. //this.actions = _self.explorer.actions;
  654. this.category = _self;
  655. this.options.id = form.id;
  656. this.column = _self.data;
  657. this.application = _self.data;
  658. }
  659. };
  660. this.app.desktop.openApplication(null, "cms.FormDesigner", options);
  661. }.bind(this));
  662. },
  663. clickColumnNode: function (_self, el, e, currentCategoryId) {
  664. /*
  665. _self.app.columns.each(function( column ){
  666. if( column.selected ){
  667. column.itemNode.setStyles( _self.app.css.columnItemNode );
  668. }
  669. })
  670. this.selected = true;
  671. el.setStyles( _self.app.css.columnItemNode_select );
  672. */
  673. var appId = "cms.ColumnManager" + this.data.id;
  674. if (this.app.desktop.apps[appId]) {
  675. var app = this.app.desktop.apps[appId];
  676. if( app && app.setCurrent )app.setCurrent();
  677. if( currentCategoryId ){
  678. if( app && app.setCategory ){
  679. app.setCategory( currentCategoryId );
  680. }
  681. }
  682. } else {
  683. this.app.desktop.openApplication(e, "cms.ColumnManager", {
  684. "currentCategoryId" : currentCategoryId,
  685. "column": {"id": this.data.id, "appName": this.data.appName, "appIcon": this.data.appIcon},
  686. "appId": appId,
  687. "onQueryLoad": function () {
  688. this.status = {"navi": 0};
  689. }
  690. });
  691. }
  692. },
  693. checkDeleteColumn: function () {
  694. if (this.deleteElements.length) {
  695. if (!this.deleteElementsNode) {
  696. this.deleteElementsNode = new Element("div", {
  697. "styles": this.app.css.deleteElementsNode,
  698. "text": this.lp.deleteElements
  699. }).inject(this.node);
  700. this.deleteElementsNode.position({
  701. relativeTo: this.container,
  702. position: "centerTop",
  703. edge: "centerbottom"
  704. });
  705. this.deleteElementsNode.addEvent("click", function (e) {
  706. this["delete"]();
  707. }.bind(this));
  708. }
  709. } else {
  710. if (this.deleteElementsNode) {
  711. this.deleteElementsNode.destroy();
  712. this.deleteElementsNode = null;
  713. delete this.deleteElementsNode;
  714. }
  715. }
  716. },
  717. deleteColumn: function (e) {
  718. var _self = this;
  719. this.app.confirm("warn", e, this.lp.delete_confirm_title,
  720. this.lp.delete_confirm_content, 320, 100, function () {
  721. _self._deleteElement();
  722. this.close();
  723. }, function( ) {
  724. this.close();
  725. }
  726. )
  727. },
  728. _deleteElement: function (id, success, failure) {
  729. this.app.restActions.removeColumn( id || this.data.id, function () {
  730. this.app.reloadTop(null, null, true);
  731. this.destroy();
  732. if (success) success();
  733. }.bind(this), function( error ){
  734. var errorObj = JSON.parse( error.responseText );
  735. this.app.notice(errorObj.message , "error");
  736. if(failure)failure();
  737. }.bind(this));
  738. },
  739. destroy: function () {
  740. this.node.destroy();
  741. MWF.release(this);
  742. delete this;
  743. }
  744. });
  745. MWF.xApplication.cms.Column.PopupForm = new Class({
  746. Extends: MPopupForm,
  747. Implements: [Options, Events],
  748. options: {
  749. "style": "blue",
  750. "width": "650",
  751. "height": "630",
  752. "hasTop": true,
  753. "hasIcon": false,
  754. "hasTopContent" : true,
  755. "hasBottom": true,
  756. //"title": MWF.xApplication.cms.Index.LP.createDocument,
  757. "draggable": true,
  758. "closeAction": true
  759. },
  760. _createTableContent: function () {
  761. MWF.xDesktop.requireApp("Template", "MDomItem", null, false);
  762. if (this.isNew) {
  763. var columnName = "";
  764. var alias = "";
  765. var memo = "";
  766. var order = "";
  767. var creator = "";
  768. var icon = "";
  769. var createTime = "";
  770. var type = "";
  771. var editform = "";
  772. var readform = "";
  773. } else {
  774. var columnName = this.data.appName;
  775. var alias = this.data.appAlias || "";
  776. var memo = this.data.description;
  777. var order = this.data.appInfoSeq;
  778. var creator = this.data.creatorUid;
  779. var createTime = this.data.createTime;
  780. var type = this.data.appType || "";
  781. var editform = this.data.defaultEditForm || "";
  782. var readform = this.data.defaultReadForm || "";
  783. }
  784. var inputStyle = "width: 96%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; height: 26px";
  785. var titleStyle = "font-size:16px; height: 40px; line-height: 40px; text-align: left";
  786. var contentStyle = "text-align: left;"
  787. var clearStyle = "position:absolute;cursor:pointer;width:26px;height:26px;right:10px;top:1px;background:url(../x_component_Template/$MPopupForm/report/icon/icon_off.png) center center no-repeat"
  788. var inputFormStyle = "width: calc( 96% - 20px); border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; height: 26px; padding-right:20px;";
  789. var html = "<table width='100%' height='90%' border='0' cellPadding='0' cellSpacing='0'>" +
  790. "<tr>" +
  791. " <td style='font-size:16px; height: 40px; line-height: 40px; text-align: left; min-width: 80px; width:26%'>" + this.lp.nameLabel + ":</td>" +
  792. " <td style='"+contentStyle+"'>" +
  793. " <input type='text' id='createColumnName' style='"+inputStyle+"' value='" + columnName + "'/>" +
  794. " </td>" +
  795. "</tr>" +
  796. "<tr>" +
  797. " <td style='"+titleStyle+"'>" + this.lp.aliasLabel + ":</td>" +
  798. " <td style='"+contentStyle+"'>" +
  799. " <input type='text' id='createColumnAlias' style='"+inputStyle+"' value='" + alias + "'/>" +
  800. " </td>" +
  801. "</tr>" +
  802. "<tr>" +
  803. " <td style='"+titleStyle+"'>" + this.lp.descriptionLabel + ":</td>" +
  804. " <td style='"+contentStyle+"'>" +
  805. " <input type='text' id='createColumnDescription' style='"+inputStyle+"' value='" + memo + "'/>" +
  806. " </td>" +
  807. "</tr>" +
  808. "<tr>" +
  809. " <td style='"+titleStyle+"'>" + this.lp.sortLabel + ":</td>" +
  810. " <td style='"+contentStyle+"'>" +
  811. " <input type='text' id='createColumnSort' style='"+inputStyle+"' value='" + order + "'/>" +
  812. " </td>" +
  813. "</tr>" +
  814. "<tr>" +
  815. " <td style='"+titleStyle+"'>" + this.lp.typeLabel + ":</td>" +
  816. " <td style='"+contentStyle+"'>" +
  817. " <input type='text' id='createColumnType' style='"+inputStyle+"' value='" + type + "'/>" +
  818. " </td>" +
  819. "</tr>" +
  820. "<tr>" +
  821. " <td style='"+titleStyle+"'>" + this.lp.editform + ":</td>" +
  822. " <td style='"+contentStyle+"'>" +
  823. ( this.isNew ?
  824. " <div style='position: relative;'><input type='text' readonly id='formEditform' style='"+inputFormStyle+"' value='" + editform + "'/><div id='formClearEditform' style='"+clearStyle+"'></div></div>" :
  825. " <select id='formEditform' style='"+inputStyle+"'></select>"
  826. ) +
  827. " <div style='text-align: left;padding-left: 2.5%;font-size: 14px;color:#999;margin-bottom: 5px;'>"+this.lp.editformNote +"</div>"+
  828. " </td>" +
  829. "</tr>" +
  830. "<tr>" +
  831. " <td style='"+titleStyle+"'>" + this.lp.readform + ":</td>" +
  832. " <td style='"+contentStyle+"'>" +
  833. ( this.isNew ?
  834. " <div style='position: relative;'><input type='text' readonly id='formReadform' style='"+inputFormStyle+"' value='" + readform + "'/><div id='formClearReadform' style='"+clearStyle+"'></div></div>" :
  835. " <select id='formReadform' style='"+inputStyle+"'></select>"
  836. ) +
  837. " <div style='text-align: left;padding-left: 2.5%;font-size: 14px;color:#999;margin-bottom: 5px;'>"+this.lp.readformNote +"</div>"+
  838. " </td>" +
  839. "</tr>" +
  840. "<tr>" +
  841. " <td style='"+titleStyle+"'>" + this.lp.iconLabel + ":</td>" +
  842. " <td style='"+contentStyle+"'>" +
  843. " <div id='formIconPreview'></div>" +
  844. " <div id='formChangeIconAction'></div>" +
  845. " </td>" +
  846. "</tr>" +
  847. "</table>";
  848. this.formTableArea.set("html", html);
  849. this.setContent();
  850. this.setIconContent();
  851. this.setDefaultFormContent();
  852. },
  853. _setCustom: function(){
  854. this.formTableContainer.setStyles({
  855. "padding-top" : "15px",
  856. "width" : "470px"
  857. });
  858. this.formBottomNode.setStyles({
  859. "padding-right" : "170px",
  860. "padding-bottom" : "50px"
  861. });
  862. },
  863. setContent: function(){
  864. this.nameInput = this.formTableArea.getElementById("createColumnName");
  865. this.aliasInput = this.formTableArea.getElementById("createColumnAlias");
  866. this.descriptionInput = this.formTableArea.getElementById("createColumnDescription");
  867. this.sortInput = this.formTableArea.getElementById("createColumnSort");
  868. this.typeInput = this.formTableArea.getElementById("createColumnType");
  869. },
  870. setIconContent: function(){
  871. this.iconPreviewNode = this.formTableArea.getElement("div#formIconPreview");
  872. this.iconActionNode = this.formTableArea.getElement("div#formChangeIconAction");
  873. this.iconPreviewNode.setStyles({
  874. "margin-left" : "20px",
  875. "margin-top" : "10px",
  876. "height": "72px",
  877. "width": "72px",
  878. "float": "left"
  879. });
  880. if (!this.isNew && this.data.appIcon) {
  881. this.iconPreviewNode.setStyle("background", "url(data:image/png;base64," + this.data.appIcon + ") center center no-repeat");
  882. } else {
  883. this.iconPreviewNode.setStyle("background", "url(" + "../x_component_cms_Column/$Main/default/icon/column.png) center center no-repeat")
  884. }
  885. var changeIconAction = new Element("div", {
  886. "styles": {
  887. "margin-left": "20px",
  888. "float": "left",
  889. "background-color": "#FFF",
  890. "padding": "4px 14px",
  891. "border": "1px solid #999",
  892. "border-radius": "3px",
  893. "margin-top": "25px",
  894. "font-size": "14px",
  895. "color": "#666",
  896. "cursor": "pointer"
  897. },
  898. "text": this.lp.changeIcon
  899. }).inject(this.iconActionNode);
  900. changeIconAction.addEvent("click", function () {
  901. this.changeIcon();
  902. }.bind(this));
  903. },
  904. setDefaultFormContent: function(){
  905. this.formEditformInput = this.formTableArea.getElement("#formEditform");
  906. if( this.isNew ){
  907. this.formEditformInput.addEvent("click", function(){
  908. this.selectDefaultForm(function (object) {
  909. this.editformTemplate = object;
  910. this.formEditformInput.set("value", object.title);
  911. }.bind(this))
  912. }.bind(this))
  913. }else{
  914. this.createFormSelect(this.formEditformInput, "edit")
  915. }
  916. this.formReadformInput = this.formTableArea.getElement("#formReadform");
  917. if( this.isNew ) {
  918. this.formReadformInput.addEvent("click", function () {
  919. this.selectDefaultForm(function (object) {
  920. this.readformTemplate = object;
  921. this.formReadformInput.set("value", object.title);
  922. }.bind(this))
  923. }.bind(this))
  924. }else{
  925. this.createFormSelect(this.formReadformInput, "read");
  926. }
  927. if(this.isNew){
  928. this.listFormTemplate(function () {
  929. this.formTemplateList.each(function(form){
  930. if(form.defaultEditForm){
  931. this.editformTemplate = {"template": form.name, "title": form.title, "type":"default"};
  932. this.formEditformInput.set("value", form.title);
  933. }
  934. if(form.defaultReadForm){
  935. this.readformTemplate = {"template": form.name, "title": form.title, "type":"default"};
  936. this.formReadformInput.set("value", form.title);
  937. }
  938. }.bind(this))
  939. }.bind(this))
  940. this.formTableArea.getElement("#formClearEditform").addEvent("click", function(){
  941. this.editformTemplate = null;
  942. this.formEditformInput.set("value", "");
  943. }.bind(this))
  944. this.formTableArea.getElement("#formClearReadform").addEvent("click", function(){
  945. this.readformTemplate = null;
  946. this.formReadformInput.set("value", "");
  947. }.bind(this))
  948. }
  949. },
  950. listFormTemplate: function(callback){
  951. if (this.formTemplateList){
  952. if (callback) callback();
  953. }else{
  954. if( !MWF.xApplication.cms.ColumnManager || !MWF.xApplication.cms.ColumnManager.LP ){
  955. MWF.requireApp("cms.ColumnManager", "lp."+o2.language, null, false);
  956. }
  957. var url = "../x_component_cms_FormDesigner/Module/Form/template/templates.json";
  958. MWF.getJSON(url, function(json){
  959. this.formTemplateList = json;
  960. if (callback) callback();
  961. }.bind(this));
  962. }
  963. },
  964. createFormSelect: function(selectNode, type){
  965. this.listForm(function () {
  966. new Element("option", {
  967. "text": "",
  968. "value": "",
  969. }).inject(selectNode)
  970. this.formList.each(function (form) {
  971. var selected = false;
  972. if( type === "edit" ){
  973. if( this.data.defaultEditForm === form.id )selected = true;
  974. }else{
  975. if( this.data.defaultReadForm === form.id )selected = true;
  976. }
  977. new Element("option", {
  978. "text": form.name,
  979. "value": form.id,
  980. "selected": selected
  981. }).inject(selectNode)
  982. }.bind(this))
  983. }.bind(this))
  984. this.addEvent("queryClose", function () {
  985. selectNode.destroy();
  986. }.bind(this))
  987. },
  988. getFormName: function(id, callback){
  989. this.listForm(function(){
  990. for( var i=0; i<this.formList.length; i++ ){
  991. if( this.formList[i].id === id )callback(this.formList[i].appName);
  992. }
  993. callback("")
  994. }.bind(this))
  995. },
  996. listForm: function( callback ){
  997. if( this.formList ){
  998. callback( this.formList );
  999. return;
  1000. }
  1001. this.app.restActions.listForm(this.data.id, function(json){
  1002. this.formList = json.data;
  1003. callback( this.formList );
  1004. }.bind(this));
  1005. },
  1006. selectDefaultForm: function(callback){
  1007. var _self = this;
  1008. MWF.requireApp("cms.ColumnManager", "widget.CMSFormTemplateSelector", null, false);
  1009. new MWF.xApplication.cms.ColumnManager.CMSFormTemplateSelector(this.app, {
  1010. onSelectDefaultForm: function (template, title) {
  1011. if(callback)callback({"template": template, "title": title, "type":"default"})
  1012. },
  1013. onSelectForm: function (template, title) {
  1014. if(callback)callback({"template": template, "title": title})
  1015. }
  1016. }).load();
  1017. },
  1018. cancel: function (e) {
  1019. this.fireEvent("queryCancel");
  1020. if (this.isNew) {
  1021. this.cancelNewColumn(e)
  1022. } else {
  1023. this.close();
  1024. }
  1025. this.fireEvent("postCancel");
  1026. },
  1027. cancelNewColumn: function (e) {
  1028. var _self = this;
  1029. if (this.nameInput.get("value") || this.descriptionInput.get("value")) {
  1030. this.app.confirm("warn", e, this.lp.create_cancel_title,
  1031. this.lp.create_cancel, 320, 100, function () {
  1032. _self.close();
  1033. this.close();
  1034. }, function () {
  1035. this.close();
  1036. });
  1037. } else {
  1038. _self.close();
  1039. }
  1040. },
  1041. ok: function (e) {
  1042. this.fireEvent("queryOk");
  1043. var data = {
  1044. "id": (this.data && this.data.id) ? this.data.id : this.app.restActions.getUUID(),
  1045. "isNewColumn": this.isNew,
  1046. "appName": this.nameInput.get("value"),
  1047. "appAlias": this.aliasInput.get("value"),
  1048. "alias": this.aliasInput.get("value"),
  1049. "description": this.descriptionInput.get("value"),
  1050. "appInfoSeq": this.sortInput.get("value"),
  1051. "appType" : this.typeInput.get("value")
  1052. };
  1053. if( !this.isNew ){
  1054. this.formEditformInput.getElements("option").each(function (option) {
  1055. if(option.selected)data.defaultEditForm = option.value;
  1056. })
  1057. this.formReadformInput.getElements("option").each(function (option) {
  1058. if(option.selected)data.defaultReadForm = option.value;
  1059. })
  1060. }
  1061. if( this.data && this.data.appIcon )data.appIcon = this.data.appIcon;
  1062. if (!data.appName) {
  1063. this.app.notice( this.lp.inputName );
  1064. return;
  1065. }else{
  1066. var callback = function ( id ) {
  1067. this.app.restActions.getColumn( id, function (json) {
  1068. //保存当前用户为管理员
  1069. if (this.isNew) {
  1070. // var data = {
  1071. // personList : [ layout.desktop.session.user.distinguishedName || "xadmin" ],
  1072. // unitList : [],
  1073. // groupList : []
  1074. // };
  1075. // this.app.restActions.saveAppInfoManager(json.data.id, data, function (js) {
  1076. // }.bind(this), null, false);
  1077. }
  1078. if (this.app.noElementNode)this.app.noElementNode.destroy();
  1079. if( this.formMaskNode )this.formMaskNode.destroy();
  1080. this.formAreaNode.destroy();
  1081. if( this.app )this.app.notice(this.isNew ? this.lp.createColumnSuccess : this.lp.updateColumnSuccess, "success");
  1082. if( this.isNew ){
  1083. var column = new MWF.xApplication.cms.Column.Column(this.app, json.data, {"where": "top"});
  1084. column.load();
  1085. this.app.columns.push(column);
  1086. this.app.reloadTop(null, null, true);
  1087. }else{
  1088. this.app.reload();
  1089. }
  1090. this.fireEvent("postOk");
  1091. }.bind(this));
  1092. }.bind(this);
  1093. this.app.restActions.saveColumn(data, function (json) {
  1094. if(!data)data.id = json.data.id;
  1095. if (json.type == "error") {
  1096. this.app.notice(json.message, "error");
  1097. } else {
  1098. this.saveForm(data, function () {
  1099. if (this.formData) {
  1100. this.saveIcon(json.data.id, callback);
  1101. } else {
  1102. callback( json.data.id );
  1103. }
  1104. }.bind(this))
  1105. }
  1106. // this.app.processConfig();
  1107. }.bind(this), function( errorObj ){
  1108. var error = JSON.parse( errorObj.responseText );
  1109. this.app.notice( error.message || json.userMessage, "error" );
  1110. }.bind(this));
  1111. }
  1112. },
  1113. changeIcon: function () {
  1114. if (!this.uploadFileAreaNode) {
  1115. this.uploadFileAreaNode = new Element("div");
  1116. var html = "<input name=\"file\" type=\"file\"/>";
  1117. this.uploadFileAreaNode.set("html", html);
  1118. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  1119. this.fileUploadNode.addEvent("change", function () {
  1120. var files = fileNode.files;
  1121. if (files.length) {
  1122. for (var i = 0; i < files.length; i++) {
  1123. var file = files.item(i);
  1124. if (!file.type.match('image.*'))continue;
  1125. this.file = file;
  1126. this.formData = new FormData();
  1127. this.formData.append('file', this.file);
  1128. if (!window.FileReader) continue;
  1129. var reader = new FileReader();
  1130. reader.onload = (function (theFile) {
  1131. return function (e) {
  1132. this.iconPreviewNode.setStyle("background", "");
  1133. this.iconPreviewNode.empty();
  1134. new Element("img", {
  1135. "styles": {
  1136. "height": "72px",
  1137. "width": "72px"
  1138. },
  1139. "src": e.target.result
  1140. }).inject(this.iconPreviewNode);
  1141. }.bind(this);
  1142. }.bind(this))(file);
  1143. reader.readAsDataURL(file);
  1144. }
  1145. }
  1146. }.bind(this));
  1147. }
  1148. var fileNode = this.uploadFileAreaNode.getFirst();
  1149. fileNode.click();
  1150. },
  1151. saveIcon: function (id, callback) {
  1152. this.app.restActions.updataColumnIcon(id, function () {
  1153. this.formData = null;
  1154. if (callback)callback( id );
  1155. }.bind(this), null, this.formData, this.file);
  1156. },
  1157. saveForm: function ( columnData, callback ) {
  1158. var editDone, readDone;
  1159. var editFormId, readFormId;
  1160. var saveColumn = function () {
  1161. if( editFormId || readFormId ){
  1162. columnData.defaultEditForm = editFormId;
  1163. columnData.defaultReadForm = readFormId;
  1164. this.app.restActions.saveColumn(columnData, function (json) {
  1165. callback()
  1166. }.bind(this), function( errorObj ){
  1167. var error = JSON.parse( errorObj.responseText );
  1168. this.app.notice( error.message || json.userMessage, "error" );
  1169. }.bind(this));
  1170. }else{
  1171. callback()
  1172. }
  1173. }.bind(this)
  1174. var saveEditDone = function (formId) {
  1175. editFormId = formId;
  1176. editDone = true;
  1177. if( editDone && readDone )saveColumn(editFormId, readFormId);
  1178. }.bind(this)
  1179. var saveReadDone = function (formId) {
  1180. readFormId = formId;
  1181. readDone = true;
  1182. if( editDone && readDone )saveColumn(editFormId, readFormId);
  1183. }.bind(this)
  1184. if( this.editformTemplate ){
  1185. if( this.editformTemplate.type === "default" ){
  1186. this.saveNewFormData( columnData, this.editformTemplate.template, saveEditDone )
  1187. }else{
  1188. this.saveNewFormDataFormTemplate( columnData, this.editformTemplate.template, saveEditDone )
  1189. }
  1190. }else{
  1191. saveEditDone();
  1192. }
  1193. if( this.readformTemplate ){
  1194. if( this.readformTemplate.type === "default" ){
  1195. this.saveNewFormData( columnData, this.readformTemplate.template, saveReadDone )
  1196. }else{
  1197. this.saveNewFormDataFormTemplate( columnData, this.readformTemplate.template, saveReadDone )
  1198. }
  1199. }else{
  1200. saveReadDone();
  1201. }
  1202. },
  1203. saveNewFormData: function(columnData, templateId, callback){
  1204. var url = "../x_component_cms_FormDesigner/Module/Form/template/"+templateId;
  1205. //MWF.getJSON("../x_component_process_FormDesigner/Module/Form/template.json", {
  1206. MWF.getJSON(url, {
  1207. "onSuccess": function(obj){
  1208. if (obj) this.saveFormAsNew(columnData, obj, callback)
  1209. }.bind(this),
  1210. "onerror": function(text){
  1211. this.notice(text, "error");
  1212. }.bind(this),
  1213. "onRequestFailure": function(xhr){
  1214. this.notice(xhr.responseText, "error");
  1215. }.bind(this)
  1216. });
  1217. },
  1218. saveNewFormDataFormTemplate: function(columnData, templateId, callback){
  1219. this.actions.getFormTemplate(templateId, function(form){
  1220. if (form) this.saveFormAsNew(columnData, form, callback)
  1221. }.bind(this));
  1222. },
  1223. saveFormAsNew: function(columnData, form, success, failure) {
  1224. debugger;
  1225. var id = columnData.id;
  1226. var name = columnData.appName;
  1227. var pcdata, mobiledata;
  1228. if (form.data) {
  1229. if (form.data.data) pcdata = JSON.decode(MWF.decodeJsonString(form.data.data));
  1230. if (form.data.mobileData) mobiledata = JSON.decode(MWF.decodeJsonString(form.data.mobileData));
  1231. } else {
  1232. pcdata = form.pcData;
  1233. mobiledata = form.mobileData;
  1234. }
  1235. if (pcdata){
  1236. pcdata.id = "";
  1237. pcdata.isNewForm = true;
  1238. pcdata.json.id = "";
  1239. pcdata.json.application = id;
  1240. pcdata.json.applicationName = name;
  1241. pcdata.json.appId = id;
  1242. pcdata.json.appName = name;
  1243. // pcdata.json.alias = "";
  1244. pcdata.json.name = pcdata.json.name.replace("模板", "")
  1245. }
  1246. if(mobiledata){
  1247. mobiledata.json.id = "";
  1248. mobiledata.json.application = id;
  1249. mobiledata.json.applicationName = name;
  1250. mobiledata.applicationName = name;
  1251. mobiledata.json.appId = id;
  1252. mobiledata.json.appName = name;
  1253. // mobiledata.json.alias = "";
  1254. mobiledata.json.name = pcdata.json.name
  1255. }
  1256. this.app.restActions.saveForm(pcdata, mobiledata, form.fieldList, function(json){
  1257. if (success) success(json.data.id);
  1258. }.bind(this), function(){
  1259. if (failure) failure();
  1260. }.bind(this));
  1261. }
  1262. });