Main.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  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. },
  39. reload: function(){
  40. this.columnContentAreaNode.empty();
  41. this.createColumnNodes();
  42. },
  43. loadApplicationContent: function () {
  44. //this.columnAreaNode = new Element("div", {
  45. // "styles": this.css.columnAreaNode
  46. //}).inject(this.node);
  47. this.loadTopNode();
  48. //this.setColumnAreaSize();
  49. //this.addEvent("resize", this.setColumnAreaSize);
  50. this.loadColumnContentArea();
  51. //this.setColumnContentSize();
  52. this.setContentSize();
  53. this.addEvent("resize", function(){
  54. this.setContentSize();
  55. }.bind(this));
  56. },
  57. loadTopNode: function(){
  58. this.columnToolbarAreaNode = new Element("div", {
  59. "styles": this.css.columnToolbarAreaNode
  60. }).inject(this.node);
  61. if (MWF.AC.isCMSManager()) {
  62. this.createColumnNode = new Element("div", {
  63. "styles": this.css.createColumnNode,
  64. "text": this.lp.column.create
  65. }).inject(this.columnToolbarAreaNode);
  66. this.createColumnNode.addEvents({
  67. "mouseover" : function(){
  68. this.createColumnNode.setStyles( this.css.createColumnNode_over );
  69. }.bind(this),
  70. "mouseout" : function(){
  71. this.createColumnNode.setStyles( this.css.createColumnNode );
  72. }.bind(this),
  73. "click": function () {
  74. this.createColumn();
  75. }.bind(this)
  76. });
  77. }
  78. this.columnToolbarTextNode = new Element("div", {
  79. "styles": this.css.columnToolbarTextNode,
  80. "text": this.lp.column.title
  81. }).inject(this.columnToolbarAreaNode);
  82. },
  83. setContentSize: function(){
  84. var nodeSize = this.node.getSize();
  85. var titlebarSize = this.columnToolbarAreaNode ? this.columnToolbarAreaNode.getSize() : {"x":0,"y":0};
  86. this.scrollNode.setStyle("height", ""+(nodeSize.y-titlebarSize.y)+"px");
  87. if (this.contentWarpNode){
  88. var count = (nodeSize.x/287).toInt();
  89. var x = 287 * count;
  90. var m = (nodeSize.x-x)/2-10;
  91. this.contentWarpNode.setStyles({
  92. "width": ""+x+"px",
  93. "margin-left": ""+m+"px"
  94. });
  95. //this.titleBar.setStyles({
  96. // "margin-left": ""+(m+10)+"px",
  97. // "margin-right": ""+(m+10)+"px"
  98. //})
  99. }
  100. },
  101. //setColumnAreaSize: function () {
  102. // var nodeSize = this.node.getSize();
  103. // var toolbarSize = this.columnToolbarAreaNode.getSize();
  104. // var y = nodeSize.y - toolbarSize.y;
  105. //
  106. // this.columnAreaNode.setStyle("height", "" + y + "px");
  107. //
  108. // if (this.columnContentAreaNode) {
  109. // var count = (nodeSize.x / 282).toInt();
  110. // var x = 282 * count;
  111. // var m = (nodeSize.x - x) / 2 - 10;
  112. // this.columnContentAreaNode.setStyles({
  113. // //"width": ""+x+"px",
  114. // "margin-left": "" + m + "px"
  115. // });
  116. // }
  117. //},
  118. //setColumnContentSize: function () {
  119. // var nodeSize = this.node.getSize();
  120. // if (this.columnContentAreaNode) {
  121. // var count = (nodeSize.x / 282).toInt();
  122. // var x = 282 * count;
  123. // var m = (nodeSize.x - x) / 2 - 10;
  124. // this.columnContentAreaNode.setStyles({
  125. // //"width": ""+x+"px",
  126. // "margin-left": "" + m + "px"
  127. // });
  128. // }
  129. //},
  130. loadColumnContentArea: function () {
  131. this.scrollNode = new Element("div", {
  132. "styles": this.css.scrollNode
  133. }).inject(this.node);
  134. this.contentWarpNode = new Element("div", {
  135. "styles": this.css.contentWarpNode
  136. }).inject(this.scrollNode);
  137. this.contentContainerNode = new Element("div",{
  138. "styles" : this.css.contentContainerNode
  139. }).inject(this.contentWarpNode);
  140. this.columnContentAreaNode = new Element("div", {
  141. "styles": this.css.columnContentAreaNode
  142. }).inject(this.contentContainerNode);
  143. //this.loadController(function () {
  144. this.createColumnNodes();
  145. //}.bind(this));
  146. //MWF.require("MWF.widget.DragScroll", function(){
  147. // new MWF.widget.DragScroll(this.columnContentAreaNode);
  148. //}.bind(this));
  149. //MWF.require("MWF.widget.ScrollBar", function () {
  150. // new MWF.widget.ScrollBar(this.columnContentAreaNode);
  151. //}.bind(this));
  152. },
  153. //loadController: function (callback) {
  154. //this.availableApp = [];
  155. //this.restActions.listAppByManager( function( json ){
  156. // (json.data||[]).each(function (d) {
  157. // this.availableApp.push(d.id);
  158. // }.bind(this));
  159. // if (callback)callback();
  160. //}.bind(this), null, true );
  161. //this.restActions.listControllerByPerson(layout.desktop.session.user.distinguishedName, function (json) {
  162. // if (json && json.data && json.data.length) {
  163. // json.data.each(function (d) {
  164. // this.availableApp.push(d.objectId);
  165. // }.bind(this))
  166. // }
  167. // if (callback)callback();
  168. //}.bind(this), null, true)
  169. //},
  170. //hasPermision: function (appId) {
  171. // return this.isAdmin || this.availableApp.contains(appId);
  172. //},
  173. createColumnNodes: function () {
  174. this.restActions.listAppByManager(function (json){
  175. var emptyColumn = null;
  176. if (json && json.data && json.data.length) {
  177. var tmpArr = json.data;
  178. tmpArr.sort(function(a , b ){
  179. return parseFloat( a.appInfoSeq ) - parseFloat(b.appInfoSeq);
  180. });
  181. json.data = tmpArr;
  182. json.data.each(function (column, index) {
  183. ///if (this.hasPermision(column.id)) {
  184. this.index = index;
  185. var column = new MWF.xApplication.cms.Column.Column(this, column, {index : index});
  186. column.load();
  187. this.columns.push(column);
  188. //}
  189. }.bind(this));
  190. }
  191. if (this.columns.length == 0) {
  192. this.noElementNode = new Element("div", {
  193. "styles": this.css.noElementNode,
  194. "text": this.lp.column.noElement
  195. }).inject(this.columnContentAreaNode);
  196. }
  197. }.bind(this));
  198. },
  199. createColumn: function () {
  200. //var column = new MWF.xApplication.cms.Column.Column(this, null, { index: ++this.index });
  201. //column.createColumn(this.node);
  202. var form = new MWF.xApplication.cms.Column.PopupForm(this, {}, {
  203. title : this.lp.column.create
  204. }, {
  205. app : this,
  206. container : this.content,
  207. lp : this.lp.column,
  208. css : {},
  209. actions : this.restActions
  210. });
  211. form.create();
  212. }
  213. /*
  214. createLoadding: function(){
  215. this.loaddingNode = new Element("div", {
  216. "styles": this.css.noApplicationNode,
  217. "text": this.lp.loadding
  218. }).inject(this.applicationContentNode);
  219. },
  220. removeLoadding: function(){
  221. if (this.loaddingNode) this.loaddingNode.destroy();
  222. },
  223. */
  224. });
  225. MWF.xApplication.cms.Column.Column = new Class({
  226. Implements: [Options, Events],
  227. options: {
  228. "where": "bottom",
  229. "index" : 1
  230. },
  231. initialize: function (app, data, options) {
  232. this.setOptions(options);
  233. this.app = app;
  234. this.container = this.app.columnContentAreaNode;
  235. this.data = data;
  236. this.isNew = false;
  237. this.lp = this.app.lp.column;
  238. },
  239. load: function () {
  240. this.data.name = this.data.appName;
  241. var columnName = this.data.appName;
  242. var alias = this.data.appAlias;
  243. var memo = this.data.description;
  244. var order = this.data.appInfoSeq;
  245. var creator = this.data.creatorUid;
  246. var createTime = this.data.createTime;
  247. //var icon = this.data.appIcon;
  248. //if( !icon || icon == "")icon = this.app.defaultColumnIcon;
  249. var itemNode = this.node = new Element("div.columnItem", {
  250. "styles": this.app.css.columnItemNode
  251. }).inject(this.container, this.options.where);
  252. itemNode.store("columnName", columnName);
  253. //itemNode.setStyle("background-color", this.options.bgColor[(Math.random()*10).toInt()]);
  254. var topNode = new Element("div", {
  255. "styles": this.app.css.columnItemTopNode
  256. }).inject(itemNode);
  257. if( this.data.iconColor ){
  258. topNode.setStyle("background-color" , "rgba("+ this.data.iconColor +",1)" )
  259. }
  260. var titleNode = new Element("div", {
  261. "styles": this.app.css.columnItemTitleNode,
  262. "text": columnName,
  263. "title": (alias) ? columnName + " (" + alias + ") " : columnName
  264. }).inject(topNode);
  265. var iconAreaNode = new Element("div",{
  266. "styles": this.app.css.columnItemIconAreaNode
  267. }).inject(itemNode);
  268. if( this.data.iconColor ){
  269. iconAreaNode.setStyle("border-color" , "rgba("+ this.data.iconColor +",1)" )
  270. }
  271. var iconNode = this.iconNode = new Element("div", {
  272. "styles": this.app.css.columnItemIconNode
  273. }).inject(itemNode);
  274. //iconNode.setStyles({
  275. // "background-image" : "url("+icon+")"
  276. //});
  277. if (this.data.appIcon) {
  278. this.iconNode.setStyle("background-image", "url(data:image/png;base64," + this.data.appIcon + ")");
  279. } else {
  280. this.iconNode.setStyle("background-image", "url(" + this.app.defaultColumnIcon + ")");
  281. }
  282. this.iconNode.makeLnk({
  283. "par": this._getLnkPar()
  284. });
  285. var middleNode = new Element("div", {
  286. "styles": this.app.css.columnItemMiddleNode
  287. }).inject(itemNode);
  288. var description = ( memo && memo != "") ? memo : this.lp.noDescription;
  289. var descriptionNode = new Element("div", {
  290. "styles": this.app.css.columnItemDescriptionNode,
  291. "text": description,
  292. "title": description
  293. }).inject(middleNode);
  294. var _self = this;
  295. itemNode.addEvents({
  296. "mouseover": function () {
  297. if (!_self.selected) this.setStyles(_self.app.css.columnItemNode_over);
  298. },
  299. "mouseout": function () {
  300. if (!_self.selected) this.setStyles(_self.app.css.columnItemNode);
  301. },
  302. "click": function (e) {
  303. _self.clickColumnNode(_self, this, e)
  304. }
  305. });
  306. var bottomNode = new Element("div", {
  307. "styles": this.app.css.columnItemBottomNode
  308. }).inject(itemNode);
  309. var bottomTitleNode = new Element("div", {
  310. "styles": this.app.css.columnItemCategoryTitleNode,
  311. "text" : this.lp.category
  312. }).inject(bottomNode);
  313. var bottomContentNode_category = new Element("div", {
  314. "styles": this.app.css.columnItemCategoryContentNode
  315. }).inject(bottomNode);
  316. this.app.restActions.listCategory( this.data.id, function ( json ) {
  317. var data = json.data || [];
  318. data.each( function( category ){
  319. var bottomItemNode = new Element("div",{
  320. styles : this.app.css.columnItemBottomItemNode,
  321. text : category.name
  322. }).inject(bottomContentNode_category);
  323. bottomItemNode.addEvents( {
  324. "click": function( ev ){
  325. this.obj.clickColumnNode(this.obj, ev.target, ev, this.data.id);
  326. ev.stopPropagation();
  327. }.bind({ obj : this, data : category }),
  328. "mouseover" : function(){
  329. this.node.setStyles( this.obj.app.css.columnItemBottomItemNode_over );
  330. }.bind({ obj : this, node : bottomItemNode }),
  331. "mouseout" : function(){
  332. this.node.setStyles( this.obj.app.css.columnItemBottomItemNode );
  333. }.bind({ obj : this, node : bottomItemNode })
  334. })
  335. }.bind(this))
  336. }.bind(this) );
  337. var bottomTitleNode = new Element("div", {
  338. "styles": this.app.css.columnItemFormTitleNode,
  339. "text" : this.lp.form
  340. }).inject(bottomNode);
  341. var bottomContentNode_form = new Element("div", {
  342. "styles": this.app.css.columnItemFormContentNode
  343. }).inject(bottomNode);
  344. this.app.restActions.listForm( this.data.id, function ( json ) {
  345. var data = json.data || [];
  346. data.each( function( form ){
  347. var bottomItemNode = new Element("div",{
  348. styles : this.app.css.columnItemBottomItemNode,
  349. text : form.name
  350. }).inject(bottomContentNode_form);
  351. bottomItemNode.addEvents( {
  352. "click": function( ev ){
  353. this.obj.openForm( this.data );
  354. ev.stopPropagation();
  355. }.bind({ obj : this, data : form }),
  356. "mouseover" : function(){
  357. this.node.setStyles( this.obj.app.css.columnItemBottomItemNode_over );
  358. }.bind({ obj : this, node : bottomItemNode }),
  359. "mouseout" : function(){
  360. this.node.setStyles( this.obj.app.css.columnItemBottomItemNode );
  361. }.bind({ obj : this, node : bottomItemNode })
  362. })
  363. }.bind(this))
  364. }.bind(this) );
  365. if ((creator == layout.desktop.session.user.distinguishedName) || MWF.AC.isCMSManager()) {
  366. this.delAdctionNode = new Element("div.delNode", {
  367. "styles": this.app.css.columnItemDelActionNode,
  368. "title": this.lp["delete"]
  369. }).inject(itemNode);
  370. itemNode.addEvents({
  371. "mouseover": function () {
  372. this.delAdctionNode.setStyle("display","");
  373. }.bind(this),
  374. "mouseout": function () {
  375. this.delAdctionNode.setStyle("display","none");
  376. }.bind(this)
  377. });
  378. this.delAdctionNode.addEvent("click", function (e) {
  379. this.deleteColumn(e);
  380. e.stopPropagation();
  381. }.bind(this));
  382. }
  383. if ((creator == layout.desktop.session.user.distinguishedName) || MWF.AC.isCMSManager()) {
  384. this.editAdctionNode = new Element("div.editNode", {
  385. "styles": this.app.css.columnItemEditActionNode,
  386. "title": this.lp.edit
  387. }).inject(itemNode);
  388. itemNode.addEvents({
  389. "mouseover": function () {
  390. this.editAdctionNode.setStyle("display","");
  391. }.bind(this),
  392. "mouseout": function () {
  393. this.editAdctionNode.setStyle("display","none");
  394. }.bind(this)
  395. });
  396. this.editAdctionNode.addEvent("click", function (e) {
  397. this.edit(e);
  398. e.stopPropagation();
  399. }.bind(this));
  400. }
  401. //if ((creator == layout.desktop.session.user.distinguishedName) || MWF.AC.isCMSManager()) {
  402. // this.exportAdctionNode = new Element("div.exportNode", {
  403. // "styles": this.app.css.columnItemExportActionNode,
  404. // "title": this.lp.export
  405. // }).inject(itemNode);
  406. //
  407. // itemNode.addEvents({
  408. // "mouseover": function () {
  409. // this.exportAdctionNode.setStyle("display","");
  410. // }.bind(this),
  411. // "mouseout": function () {
  412. // this.exportAdctionNode.setStyle("display","none");
  413. // }.bind(this)
  414. // });
  415. // this.exportAdctionNode.addEvent("click", function (e) {
  416. // this.export(e);
  417. // e.stopPropagation();
  418. // }.bind(this));
  419. //}
  420. },
  421. _getLnkPar: function(){
  422. var lnkIcon = this.app.defaultColumnIcon;
  423. if (this.data.icon) lnkIcon = "data:image/png;base64," + this.data.appIcon;
  424. var appId = "cms.ColumnManager"+this.data.id;
  425. return {
  426. "icon": lnkIcon,
  427. "title": this.data.appName,
  428. "par": "cms.ColumnManager#{\"column\": \""+this.data.id+"\", \"appId\": \""+appId+"\"}"
  429. };
  430. },
  431. export: function(){
  432. //var applicationjson = {
  433. // "application": {},
  434. // "processList": [],
  435. // "formList": [],
  436. // "dictionaryList": [],
  437. // "scriptList": []
  438. //};
  439. //this.app.restActions.getApplication(this.data.name, function(json){
  440. //
  441. //}
  442. MWF.xDesktop.requireApp("cms.Column", "Exporter", function(){
  443. (new MWF.xApplication.cms.Column.Exporter(this.app, this.data)).load();
  444. }.bind(this));
  445. },
  446. edit : function(){
  447. var form = new MWF.xApplication.cms.Column.PopupForm(this.app, this.data, {
  448. title : this.lp.edit
  449. }, {
  450. app : this.app,
  451. container : this.app.content,
  452. lp : this.lp,
  453. css : {},
  454. actions : this.app.restActions
  455. });
  456. form.edit();
  457. },
  458. openForm: function( form ){
  459. layout.desktop.getFormDesignerStyle(function(){
  460. var _self = this;
  461. var options = {
  462. "style": layout.desktop.formDesignerStyle,
  463. "onQueryLoad": function(){
  464. //this.actions = _self.explorer.actions;
  465. this.category = _self;
  466. this.options.id = form.id;
  467. this.column = _self.data;
  468. this.application = _self.data;
  469. }
  470. };
  471. this.app.desktop.openApplication(null, "cms.FormDesigner", options);
  472. }.bind(this));
  473. },
  474. clickColumnNode: function (_self, el, e, currentCategoryId) {
  475. /*
  476. _self.app.columns.each(function( column ){
  477. if( column.selected ){
  478. column.itemNode.setStyles( _self.app.css.columnItemNode );
  479. }
  480. })
  481. this.selected = true;
  482. el.setStyles( _self.app.css.columnItemNode_select );
  483. */
  484. var appId = "cms.ColumnManager" + this.data.id;
  485. if (this.app.desktop.apps[appId]) {
  486. var app = this.app.desktop.apps[appId];
  487. app.setCurrent();
  488. if( currentCategoryId )app.setCategory( currentCategoryId );
  489. } else {
  490. this.app.desktop.openApplication(e, "cms.ColumnManager", {
  491. "currentCategoryId" : currentCategoryId,
  492. "column": this.data,
  493. "appId": appId,
  494. "onQueryLoad": function () {
  495. this.status = {"navi": 0};
  496. }
  497. });
  498. }
  499. },
  500. checkDeleteColumn: function () {
  501. if (this.deleteElements.length) {
  502. if (!this.deleteElementsNode) {
  503. this.deleteElementsNode = new Element("div", {
  504. "styles": this.app.css.deleteElementsNode,
  505. "text": this.lp.deleteElements
  506. }).inject(this.node);
  507. this.deleteElementsNode.position({
  508. relativeTo: this.container,
  509. position: "centerTop",
  510. edge: "centerbottom"
  511. });
  512. this.deleteElementsNode.addEvent("click", function (e) {
  513. this["delete"]();
  514. }.bind(this));
  515. }
  516. } else {
  517. if (this.deleteElementsNode) {
  518. this.deleteElementsNode.destroy();
  519. this.deleteElementsNode = null;
  520. delete this.deleteElementsNode;
  521. }
  522. }
  523. },
  524. deleteColumn: function (e) {
  525. var _self = this;
  526. this.app.confirm("warn", e, this.lp.delete_confirm_title,
  527. this.lp.delete_confirm_content, 320, 100, function () {
  528. _self._deleteElement();
  529. this.close();
  530. }, function( ) {
  531. this.close();
  532. }
  533. )
  534. },
  535. _deleteElement: function (id, success, failure) {
  536. this.app.restActions.removeColumn( id || this.data.id, function () {
  537. this.destroy();
  538. if (success) success();
  539. }.bind(this), function( error ){
  540. var errorObj = JSON.parse( error.responseText );
  541. this.app.notice(errorObj.message , "error");
  542. if(failure)failure();
  543. }.bind(this));
  544. },
  545. destroy: function () {
  546. this.node.destroy();
  547. MWF.release(this);
  548. delete this;
  549. }
  550. });
  551. MWF.xApplication.cms.Column.PopupForm = new Class({
  552. Extends: MPopupForm,
  553. Implements: [Options, Events],
  554. options: {
  555. "style": "blue",
  556. "width": "650",
  557. "height": "400",
  558. "hasTop": true,
  559. "hasIcon": false,
  560. "hasTopContent" : true,
  561. "hasBottom": true,
  562. //"title": MWF.xApplication.cms.Index.LP.createDocument,
  563. "draggable": true,
  564. "closeAction": true
  565. },
  566. _createTableContent: function () {
  567. if (!this.isNew) {
  568. var columnName = this.data.appName;
  569. var alias = this.data.appAlias;
  570. var memo = this.data.description;
  571. var order = this.data.appInfoSeq;
  572. var creator = this.data.creatorUid;
  573. var createTime = this.data.createTime;
  574. //var icon = this.data.appIcon;
  575. //if( !icon || icon == "")icon = this.app.defaultColumnIcon;
  576. } else {
  577. var columnName = "";
  578. var alias = "";
  579. var memo = "";
  580. var order = "";
  581. var creator = "";
  582. var icon = "";
  583. var createTime = "";
  584. }
  585. var html = "<table width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  586. "<tr><td style=\"font-size:16px; height: 40px; line-height: 40px; text-align: left; min-width: 60px; width:20%\">" +
  587. this.lp.nameLabel + ":</td>" +
  588. "<td style=\"; text-align: right;\"><input type=\"text\" id=\"createColumnName\" " +
  589. "style=\"width: 95%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  590. "height: 26px;\" value=\"" + columnName + "\"/></td></tr>" +
  591. "<tr><td style=\"font-size:16px; height: 40px; line-height: 40px; text-align: left\">" + this.lp.descriptionLabel + ":</td>" +
  592. "<td style=\"; text-align: right;\"><input type=\"text\" id=\"createColumnDescription\" " +
  593. "style=\"width: 95%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  594. "height: 26px;\" value=\"" + memo + "\"/></td></tr>" +
  595. "<tr><td style=\"font-size:16px; height: 40px; line-height: 40px; text-align: left\">" + this.lp.sortLabel + ":</td>" +
  596. "<td style=\"; text-align: right;\"><input type=\"text\" id=\"createColumnSort\" " +
  597. "style=\"width: 95%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  598. "height: 26px;\" value=\"" + order + "\"/></td></tr>" +
  599. "<tr><td style=\"font-size:16px; height: 40px; line-height: 40px; text-align: left\">" + this.lp.iconLabel + ":</td>" +
  600. "<td style=\"; text-align: right;\"><div id='formIconPreview'></div><div id='formChangeIconAction'></div></td></tr>" +
  601. "</table>";
  602. this.formTableArea.set("html", html);
  603. this.setContent();
  604. this.setIconContent();
  605. },
  606. _setCustom: function(){
  607. this.formTableContainer.setStyles({
  608. "padding-top" : "15px",
  609. "width" : "470px"
  610. });
  611. this.formBottomNode.setStyles({
  612. "padding-right" : "170px",
  613. "padding-bottom" : "50px"
  614. });
  615. },
  616. setContent: function(){
  617. this.nameInput = this.formTableArea.getElementById("createColumnName");
  618. this.descriptionInput = this.formTableArea.getElementById("createColumnDescription");
  619. this.sortInput = this.formTableArea.getElementById("createColumnSort");
  620. },
  621. setIconContent: function(){
  622. this.iconPreviewNode = this.formTableArea.getElement("div#formIconPreview");
  623. this.iconActionNode = this.formTableArea.getElement("div#formChangeIconAction");
  624. this.iconPreviewNode.setStyles({
  625. "margin-left" : "20px",
  626. "margin-top" : "10px",
  627. "height": "72px",
  628. "width": "72px",
  629. "float": "left"
  630. });
  631. if (!this.isNew && this.data.appIcon) {
  632. this.iconPreviewNode.setStyle("background", "url(data:image/png;base64," + this.data.appIcon + ") center center no-repeat");
  633. } else {
  634. this.iconPreviewNode.setStyle("background", "url(" + "/x_component_cms_Column/$Main/default/icon/column.png) center center no-repeat")
  635. }
  636. var changeIconAction = new Element("div", {
  637. "styles": {
  638. "margin-left": "20px",
  639. "float": "left",
  640. "background-color": "#FFF",
  641. "padding": "4px 14px",
  642. "border": "1px solid #999",
  643. "border-radius": "3px",
  644. "margin-top": "25px",
  645. "font-size": "14px",
  646. "color": "#666",
  647. "cursor": "pointer"
  648. },
  649. "text": "更改图标"
  650. }).inject(this.iconActionNode);
  651. changeIconAction.addEvent("click", function () {
  652. this.changeIcon();
  653. }.bind(this));
  654. },
  655. cancel: function (e) {
  656. this.fireEvent("queryCancel");
  657. if (this.isNew) {
  658. this.cancelNewColumn(e)
  659. } else {
  660. this.close();
  661. }
  662. this.fireEvent("postCancel");
  663. },
  664. cancelNewColumn: function (e) {
  665. var _self = this;
  666. if (this.nameInput.get("value") || this.descriptionInput.get("value")) {
  667. this.app.confirm("warn", e, this.lp.create_cancel_title,
  668. this.lp.create_cancel, 320, 100, function () {
  669. _self.close();
  670. this.close();
  671. }, function () {
  672. this.close();
  673. });
  674. } else {
  675. _self.close();
  676. }
  677. },
  678. ok: function (e) {
  679. this.fireEvent("queryOk");
  680. var data = {
  681. "id": (this.data && this.data.id) ? this.data.id : this.app.restActions.getUUID(),
  682. "isNewColumn": this.isNew,
  683. "appName": this.nameInput.get("value"),
  684. "description": this.descriptionInput.get("value"),
  685. "appInfoSeq": this.sortInput.get("value")
  686. };
  687. if( this.data && this.data.appIcon )data.appIcon = this.data.appIcon;
  688. if (!data.appName) {
  689. this.app.notice( this.lp.inputName );
  690. return;
  691. }else{
  692. var callback = function ( id ) {
  693. this.app.restActions.getColumn( id, function (json) {
  694. //保存当前用户为管理员
  695. if (this.isNew) {
  696. //var controllerData = {
  697. // "objectType": "APPINFO",
  698. // "objectId": json.data.id,
  699. // "adminUid": layout.desktop.session.user.distinguishedName,
  700. // "adminName": layout.desktop.session.user.distinguishedName,
  701. // "adminLevel": "ADMIN"
  702. //};
  703. //this.app.restActions.addController(controllerData);
  704. var data = {
  705. personList : [ layout.desktop.session.user.distinguishedName || "xadmin" ],
  706. unitList : [],
  707. groupList : []
  708. };
  709. this.app.restActions.saveAppInfoManager(json.data.id, data, function (js) {
  710. }.bind(this), null, false);
  711. }
  712. if (this.app.noElementNode)this.app.noElementNode.destroy();
  713. if( this.formMaskNode )this.formMaskNode.destroy();
  714. this.formAreaNode.destroy();
  715. if( this.app )this.app.notice(this.isNew ? this.lp.createColumnSuccess : this.lp.updateColumnSuccess, "success");
  716. if( this.isNew ){
  717. var column = new MWF.xApplication.cms.Column.Column(this.app, json.data, {"where": "top"});
  718. column.load();
  719. this.app.columns.push(column);
  720. }else{
  721. this.app.reload();
  722. }
  723. this.fireEvent("postOk");
  724. }.bind(this));
  725. }.bind(this);
  726. this.app.restActions.saveColumn(data, function (json) {
  727. if (json.type == "error") {
  728. this.app.notice(json.message, "error");
  729. } else {
  730. if (this.formData) {
  731. this.saveIcon(json.data.id, callback);
  732. } else {
  733. callback( json.data.id );
  734. }
  735. }
  736. // this.app.processConfig();
  737. }.bind(this), function( errorObj ){
  738. var error = JSON.parse( errorObj.responseText );
  739. this.app.notice( error.message || json.userMessage, "error" );
  740. }.bind(this));
  741. }
  742. },
  743. changeIcon: function () {
  744. if (!this.uploadFileAreaNode) {
  745. this.uploadFileAreaNode = new Element("div");
  746. var html = "<input name=\"file\" type=\"file\"/>";
  747. this.uploadFileAreaNode.set("html", html);
  748. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  749. this.fileUploadNode.addEvent("change", function () {
  750. var files = fileNode.files;
  751. if (files.length) {
  752. for (var i = 0; i < files.length; i++) {
  753. var file = files.item(i);
  754. if (!file.type.match('image.*'))continue;
  755. this.file = file;
  756. this.formData = new FormData();
  757. this.formData.append('file', this.file);
  758. if (!window.FileReader) continue;
  759. var reader = new FileReader();
  760. reader.onload = (function (theFile) {
  761. return function (e) {
  762. this.iconPreviewNode.setStyle("background", "");
  763. this.iconPreviewNode.empty();
  764. new Element("img", {
  765. "styles": {
  766. "height": "72px",
  767. "width": "72px"
  768. },
  769. "src": e.target.result
  770. }).inject(this.iconPreviewNode);
  771. }.bind(this);
  772. }.bind(this))(file);
  773. reader.readAsDataURL(file);
  774. }
  775. }
  776. }.bind(this));
  777. }
  778. var fileNode = this.uploadFileAreaNode.getFirst();
  779. fileNode.click();
  780. },
  781. saveIcon: function (id, callback) {
  782. this.app.restActions.updataColumnIcon(id, function () {
  783. this.formData = null;
  784. if (callback)callback( id );
  785. }.bind(this), null, this.formData, this.file);
  786. }
  787. });