Main.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. MWF.xApplication.cms = MWF.xApplication.cms || {};
  2. //MWF.xApplication.cms.Column = MWF.xApplication.cms.Column || {};
  3. MWF.xDesktop.requireApp("cms.Column", "Actions.RestActions", null, false);
  4. MWF.xApplication.cms.Column.Main = new Class({
  5. Extends: MWF.xApplication.Common.Main,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "name": "cms.Column",
  10. "icon": "icon.png",
  11. "width": "1000",
  12. "height": "600",
  13. "isResize": false,
  14. "isMax": true,
  15. "title": MWF.xApplication.cms.Column.LP.title,
  16. "tooltip": {
  17. "description": MWF.xApplication.cms.Column.LP.description,
  18. "column": {
  19. "title": MWF.xApplication.cms.Column.LP.column.title,
  20. "create": MWF.xApplication.cms.Column.LP.column.create,
  21. "nameLabel": MWF.xApplication.cms.Column.LP.column.nameLabel,
  22. "aliasLabel": MWF.xApplication.cms.Column.LP.column.aliasLabel,
  23. "descriptionLabel": MWF.xApplication.cms.Column.LP.column.descriptionLabel,
  24. "sortLabel": MWF.xApplication.cms.Column.LP.column.sortLabel,
  25. "iconLabel": MWF.xApplication.cms.Column.LP.column.iconLabel,
  26. "cancel": MWF.xApplication.cms.Column.LP.column.cancel,
  27. "ok": MWF.xApplication.cms.Column.LP.column.ok,
  28. "inputName": MWF.xApplication.cms.Column.LP.column.inputName,
  29. "create_cancel_title": MWF.xApplication.cms.Column.LP.column.create_cancel_title,
  30. "create_cancel": MWF.xApplication.cms.Column.LP.column.create_cancel,
  31. "noDescription": MWF.xApplication.cms.Column.LP.column.noDescription,
  32. "delete": MWF.xApplication.cms.Column.LP.column.delete,
  33. "edit": MWF.xApplication.cms.Column.LP.column.edit,
  34. "delete_confirm_content": MWF.xApplication.cms.Column.LP.column.delete_confirm_content,
  35. "delete_confirm_title": MWF.xApplication.cms.Column.LP.column.delete_confirm_title,
  36. "createColumnSuccess": MWF.xApplication.cms.Column.LP.column.createColumnSuccess,
  37. "updateColumnSuccess": MWF.xApplication.cms.Column.LP.column.updateColumnSuccess
  38. },
  39. "category": {
  40. "title": MWF.xApplication.cms.Column.LP.category.title,
  41. "create": MWF.xApplication.cms.Column.LP.category.create,
  42. "nameLabel": MWF.xApplication.cms.Column.LP.category.nameLabel,
  43. "aliasLabel": MWF.xApplication.cms.Column.LP.category.aliasLabel,
  44. "descriptionLabel": MWF.xApplication.cms.Column.LP.category.descriptionLabel,
  45. "sortLabel": MWF.xApplication.cms.Column.LP.category.sortLabel,
  46. "iconLabel": MWF.xApplication.cms.Column.LP.category.iconLabel,
  47. "columnLabel": MWF.xApplication.cms.Column.LP.category.columnLabel,
  48. "cancel": MWF.xApplication.cms.Column.LP.category.cancel,
  49. "ok": MWF.xApplication.cms.Column.LP.category.ok,
  50. "inputName": MWF.xApplication.cms.Column.LP.category.inputName,
  51. "create_cancel_title": MWF.xApplication.cms.Column.LP.category.create_cancel_title,
  52. "create_cancel": MWF.xApplication.cms.Column.LP.category.create_cancel,
  53. "noDescription": MWF.xApplication.cms.Column.LP.category.noDescription,
  54. "edit": MWF.xApplication.cms.Column.LP.category.edit
  55. }
  56. }
  57. },
  58. onQueryLoad: function () {
  59. this.lp = MWF.xApplication.cms.Column.LP;
  60. this.defaultColumnIcon = "/x_component_cms_Column/$Main/" + this.options.style + "/icon/column.png";
  61. this.defaultCategoryIcon = "/x_component_cms_Column/$Main/" + this.options.style + "/icon/category2.png";
  62. },
  63. loadApplication: function (callback) {
  64. this.isAdmin = ( MWF.AC.isProcessPlatformCreator() || MWF.AC.isAdministrator() );
  65. if (!this.restActions) this.restActions = new MWF.xApplication.cms.Column.Actions.RestActions();
  66. this.columns = [];
  67. this.categorys = [];
  68. this.deleteElements = [];
  69. this.createNode();
  70. this.loadApplicationContent();
  71. if (callback) callback();
  72. },
  73. loadApplicationContent: function () {
  74. //this.loadToolbar();
  75. this.loadColumnArea();
  76. //this.loadCategoryArea();
  77. },
  78. createNode: function () {
  79. this.content.setStyle("overflow", "hidden");
  80. this.node = new Element("div", {
  81. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  82. }).inject(this.content);
  83. },
  84. loadToolbar: function () {
  85. this.toolbarAreaNode = new Element("div", {
  86. "styles": this.css.toolbarAreaNode,
  87. "text": this.options.tooltip.description
  88. }).inject(this.node);
  89. //this.createCreateAction();
  90. //this.createSearchAction();
  91. },
  92. createCreateAction: function () {
  93. //if (MWF.AC.isProcessPlatformCreator()){
  94. this.createCategoryNode = new Element("div", {
  95. "styles": this.css.createCategoryNode,
  96. "title": this.options.tooltip.category.create
  97. }).inject(this.toolbarAreaNode);
  98. this.createCategoryNode.addEvent("click", function () {
  99. this.createCategory();
  100. }.bind(this));
  101. //}
  102. },
  103. loadColumnArea: function () {
  104. this.columnAreaNode = new Element("div", {
  105. "styles": this.css.columnAreaNode
  106. }).inject(this.node);
  107. this.columnToolbarAreaNode = new Element("div", {
  108. "styles": this.css.columnToolbarAreaNode
  109. }).inject(this.columnAreaNode);
  110. if (MWF.AC.isProcessPlatformCreator()) {
  111. if (MWF.AC.isAdministrator()) {
  112. this.createColumnNode = new Element("button", {
  113. "styles": this.css.createColumnNode,
  114. "text": this.options.tooltip.column.create
  115. }).inject(this.columnToolbarAreaNode);
  116. this.createColumnNode.addEvent("click", function () {
  117. this.createColumn();
  118. }.bind(this));
  119. }
  120. }
  121. this.columnToolbarTextNode = new Element("div", {
  122. "styles": this.css.columnToolbarTextNode,
  123. "text": this.options.tooltip.column.title
  124. }).inject(this.columnToolbarAreaNode);
  125. this.setColumnAreaSize();
  126. this.addEvent("resize", this.setColumnAreaSize);
  127. this.loadColumnContentArea();
  128. this.setColumnContentSize();
  129. },
  130. setColumnAreaSize: function () {
  131. var nodeSize = this.node.getSize();
  132. var toolbarSize = this.columnToolbarAreaNode.getSize();
  133. var y = nodeSize.y - toolbarSize.y;
  134. this.columnAreaNode.setStyle("height", "" + y + "px");
  135. if (this.columnContentAreaNode) {
  136. var count = (nodeSize.x / 282).toInt();
  137. var x = 282 * count;
  138. var m = (nodeSize.x - x) / 2 - 10;
  139. this.columnContentAreaNode.setStyles({
  140. //"width": ""+x+"px",
  141. "margin-left": "" + m + "px"
  142. });
  143. }
  144. },
  145. setColumnContentSize: function () {
  146. var nodeSize = this.node.getSize();
  147. if (this.columnContentAreaNode) {
  148. var count = (nodeSize.x / 282).toInt();
  149. var x = 282 * count;
  150. var m = (nodeSize.x - x) / 2 - 10;
  151. this.columnContentAreaNode.setStyles({
  152. //"width": ""+x+"px",
  153. "margin-left": "" + m + "px"
  154. });
  155. }
  156. },
  157. loadColumnContentArea: function () {
  158. this.columnContentAreaNode = new Element("div", {
  159. "styles": this.css.columnContentAreaNode
  160. }).inject(this.columnAreaNode);
  161. this.loadController(function () {
  162. this.createColumnNodes()
  163. }.bind(this))
  164. //MWF.require("MWF.widget.DragScroll", function(){
  165. // new MWF.widget.DragScroll(this.columnContentAreaNode);
  166. //}.bind(this));
  167. MWF.require("MWF.widget.ScrollBar", function () {
  168. new MWF.widget.ScrollBar(this.columnContentAreaNode);
  169. }.bind(this));
  170. },
  171. loadController: function (callback) {
  172. this.availableApp = [];
  173. this.restActions.listControllerByPerson(layout.desktop.session.user.name, function (json) {
  174. if (json && json.data && json.data.length) {
  175. json.data.each(function (d) {
  176. //if( d.objectType == "APPINFO"){
  177. this.availableApp.push(d.objectId)
  178. //}
  179. }.bind(this))
  180. }
  181. if (callback)callback();
  182. }.bind(this), null, true)
  183. },
  184. hasPermision: function (appId) {
  185. return this.isAdmin || this.availableApp.contains(appId);
  186. },
  187. createColumnNodes: function () {
  188. this.restActions.listColumn(function (json) {
  189. var emptyColumn = null;
  190. if (json && json.data && json.data.length) {
  191. var tmpArr = json.data;
  192. tmpArr.sort(function(a , b ){
  193. return parseFloat( a.appInfoSeq ) - parseFloat(b.appInfoSeq);
  194. })
  195. json.data = tmpArr;
  196. json.data.each(function (column) {
  197. if (this.hasPermision(column.id)) {
  198. var column = new MWF.xApplication.cms.Column.Column(this, column);
  199. column.load();
  200. this.columns.push(column);
  201. }
  202. }.bind(this));
  203. }
  204. if (this.columns.length == 0) {
  205. this.noElementNode = new Element("div", {
  206. "styles": this.css.noElementNode,
  207. "text": this.lp.column.noElement
  208. }).inject(this.columnContentAreaNode);
  209. }
  210. }.bind(this));
  211. },
  212. createColumn: function (text, alias, memo, icon, creator) {
  213. var column = new MWF.xApplication.cms.Column.Column(this);
  214. column.createColumn(this.node);
  215. },
  216. /*
  217. createLoadding: function(){
  218. this.loaddingNode = new Element("div", {
  219. "styles": this.css.noApplicationNode,
  220. "text": this.options.tooltip.loadding
  221. }).inject(this.applicationContentNode);
  222. },
  223. removeLoadding: function(){
  224. if (this.loaddingNode) this.loaddingNode.destroy();
  225. },
  226. */
  227. });
  228. MWF.xApplication.cms.Column.Column = new Class({
  229. Implements: [Options, Events],
  230. options: {
  231. "where": "bottom"
  232. },
  233. initialize: function (app, data, options) {
  234. this.setOptions(options);
  235. this.app = app;
  236. this.container = this.app.columnContentAreaNode;
  237. this.data = data;
  238. this.isNew = false;
  239. },
  240. load: function () {
  241. this.data.name = this.data.appName;
  242. var columnName = this.data.appName;
  243. var alias = this.data.appAlias;
  244. var memo = this.data.description;
  245. var order = this.data.appInfoSeq;
  246. var creator = this.data.creatorUid;
  247. var createTime = this.data.createTime;
  248. //var icon = this.data.appIcon;
  249. //if( !icon || icon == "")icon = this.app.defaultColumnIcon;
  250. var itemNode = this.node = new Element("div.columnItem", {
  251. "styles": this.app.css.columnItemNode
  252. }).inject(this.container, this.options.where);
  253. itemNode.store("columnName", columnName);
  254. //itemNode.setStyle("background-color", this.options.bgColor[(Math.random()*10).toInt()]);
  255. var iconNode = this.iconNode = new Element("div", {
  256. "styles": this.app.css.columnItemIconNode
  257. }).inject(itemNode);
  258. //iconNode.setStyles({
  259. // "background-image" : "url("+icon+")"
  260. //});
  261. if (this.data.appIcon) {
  262. this.iconNode.setStyle("background-image", "url(data:image/png;base64," + this.data.appIcon + ")");
  263. } else {
  264. this.iconNode.setStyle("background-image", "url(" + this.app.defaultColumnIcon + ")")
  265. }
  266. var textNode = new Element("div", {
  267. "styles": this.app.css.columnItemTextNode
  268. }).inject(itemNode)
  269. var titleNode = new Element("div", {
  270. "styles": this.app.css.columnItemTitleNode,
  271. "text": columnName,
  272. "title": (alias) ? columnName + " (" + alias + ") " : columnName
  273. }).inject(textNode)
  274. var description = ( memo && memo != "") ? memo : this.app.options.tooltip.column.noDescription;
  275. var descriptionNode = new Element("div", {
  276. "styles": this.app.css.columnItemDescriptionNode,
  277. "text": description,
  278. "title": description
  279. }).inject(textNode)
  280. var _self = this;
  281. itemNode.addEvents({
  282. "mouseover": function () {
  283. if (!_self.selected) this.setStyles(_self.app.css.columnItemNode_over);
  284. },
  285. "mouseout": function () {
  286. if (!_self.selected) this.setStyles(_self.app.css.columnItemNode);
  287. },
  288. "click": function (e) {
  289. _self.clickColumnNode(_self, this, e)
  290. }
  291. });
  292. if (MWF.AC.isProcessPlatformCreator()) {
  293. if ((creator == layout.desktop.session.user.name) || MWF.AC.isAdministrator()) {
  294. this.delAdctionNode = new Element("div.delNode", {
  295. "styles": this.app.css.columnItemDelActionNode,
  296. "title": this.app.options.tooltip.column.delete
  297. }).inject(itemNode);
  298. itemNode.addEvents({
  299. "mouseover": function () {
  300. this.delAdctionNode.fade("in");
  301. }.bind(this),
  302. "mouseout": function () {
  303. this.delAdctionNode.fade("out");
  304. }.bind(this)
  305. });
  306. this.delAdctionNode.addEvent("click", function (e) {
  307. this.deleteColumn(e);
  308. e.stopPropagation();
  309. }.bind(this));
  310. }
  311. }
  312. if (MWF.AC.isProcessPlatformCreator()) {
  313. if ((creator == layout.desktop.session.user.name) || MWF.AC.isAdministrator()) {
  314. this.editAdctionNode = new Element("div.editNode", {
  315. "styles": this.app.css.columnItemEditActionNode,
  316. "title": this.app.options.tooltip.column.edit
  317. }).inject(itemNode);
  318. itemNode.addEvents({
  319. "mouseover": function () {
  320. this.editAdctionNode.fade("in");
  321. }.bind(this),
  322. "mouseout": function () {
  323. this.editAdctionNode.fade("out");
  324. }.bind(this)
  325. });
  326. this.editAdctionNode.addEvent("click", function (e) {
  327. this.edit(e);
  328. e.stopPropagation();
  329. }.bind(this));
  330. }
  331. }
  332. },
  333. clickColumnNode: function (_self, el, e) {
  334. /*
  335. _self.app.columns.each(function( column ){
  336. if( column.selected ){
  337. column.itemNode.setStyles( _self.app.css.columnItemNode );
  338. }
  339. })
  340. this.selected = true;
  341. el.setStyles( _self.app.css.columnItemNode_select );
  342. */
  343. var appId = "cms.ColumnManager" + this.data.id;
  344. if (this.app.desktop.apps[appId]) {
  345. this.app.desktop.apps[appId].setCurrent();
  346. } else {
  347. this.app.desktop.openApplication(e, "cms.ColumnManager", {
  348. "column": this.data,
  349. "appId": appId,
  350. "onQueryLoad": function () {
  351. this.status = {"navi": 0};
  352. }
  353. });
  354. }
  355. },
  356. checkDeleteColumn: function () {
  357. if (this.deleteElements.length) {
  358. if (!this.deleteElementsNode) {
  359. this.deleteElementsNode = new Element("div", {
  360. "styles": this.app.css.deleteElementsNode,
  361. "text": this.app.lp.column.deleteElements
  362. }).inject(this.node);
  363. this.deleteElementsNode.position({
  364. relativeTo: this.container,
  365. position: "centerTop",
  366. edge: "centerbottom"
  367. });
  368. this.deleteElementsNode.addEvent("click", function (e) {
  369. this.delete();
  370. }.bind(this));
  371. }
  372. } else {
  373. if (this.deleteElementsNode) {
  374. this.deleteElementsNode.destroy();
  375. this.deleteElementsNode = null;
  376. delete this.deleteElementsNode;
  377. }
  378. }
  379. },
  380. deleteColumn: function (e) {
  381. var _self = this;
  382. this.app.confirm("warn", e, this.app.options.tooltip.column.delete_confirm_title,
  383. this.app.options.tooltip.column.delete_confirm_content, "320px", "100px", function () {
  384. _self._deleteElement();
  385. this.close();
  386. }, function( ) {
  387. this.close();
  388. }
  389. )
  390. },
  391. _deleteElement: function (id, success, failure) {
  392. this.app.restActions.removeColumn( id || this.data.id, function () {
  393. this.destroy();
  394. if (success) success();
  395. }.bind(this), function( error ){
  396. var errorObj = JSON.parse( error.responseText );
  397. this.app.notice(errorObj.message , "error");
  398. if(failure)failure();
  399. }.bind(this));
  400. },
  401. destroy: function () {
  402. this.node.destroy();
  403. MWF.release(this);
  404. delete this;
  405. },
  406. edit: function () {
  407. this.isNew = false;
  408. this.createContainer = this.app.node;
  409. this.createColumnCreateMarkNode();
  410. this.createColumnCreateAreaNode();
  411. this.createColumnCreateNode();
  412. this.columnCreateAreaNode.inject(this.columnCreateMarkNode, "after");
  413. this.columnCreateAreaNode.fade("in");
  414. $("createColumnName").focus();
  415. this.setColumnCreateNodeSize();
  416. this.setColumnCreateNodeSizeFun = this.setColumnCreateNodeSize.bind(this);
  417. this.addEvent("resize", this.setColumnCreateNodeSizeFun);
  418. },
  419. createColumn: function (container) {
  420. this.isNew = true;
  421. this.createContainer = container;
  422. this.createColumnCreateMarkNode();
  423. this.createColumnCreateAreaNode();
  424. this.createColumnCreateNode();
  425. this.columnCreateAreaNode.inject(this.columnCreateMarkNode, "after");
  426. this.columnCreateAreaNode.fade("in");
  427. $("createColumnName").focus();
  428. this.setColumnCreateNodeSize();
  429. this.setColumnCreateNodeSizeFun = this.setColumnCreateNodeSize.bind(this);
  430. this.addEvent("resize", this.setColumnCreateNodeSizeFun);
  431. },
  432. createColumnCreateMarkNode: function () {
  433. this.columnCreateMarkNode = new Element("div", {
  434. "styles": this.app.css.columnCreateMarkNode,
  435. "events": {
  436. "mouseover": function (e) {
  437. e.stopPropagation();
  438. },
  439. "mouseout": function (e) {
  440. e.stopPropagation();
  441. }
  442. }
  443. }).inject(this.createContainer, "after");
  444. },
  445. createColumnCreateAreaNode: function () {
  446. this.columnCreateAreaNode = new Element("div", {
  447. "styles": this.app.css.columnCreateAreaNode
  448. });
  449. },
  450. createColumnCreateNode: function () {
  451. if (!this.isNew) {
  452. var columnName = this.data.appName;
  453. var alias = this.data.appAlias;
  454. var memo = this.data.description;
  455. var order = this.data.appInfoSeq;
  456. var creator = this.data.creatorUid;
  457. var createTime = this.data.createTime;
  458. //var icon = this.data.appIcon;
  459. //if( !icon || icon == "")icon = this.app.defaultColumnIcon;
  460. } else {
  461. var columnName = "";
  462. var alias = "";
  463. var memo = "";
  464. var order = "";
  465. var creator = "";
  466. var icon = "";
  467. var createTime = "";
  468. }
  469. this.columnCreateNode = new Element("div", {
  470. "styles": this.app.css.columnCreateNode
  471. }).inject(this.columnCreateAreaNode);
  472. this.columnCreateNewNode = new Element("div", {
  473. "styles": ( this.isNew ? this.app.css.columnCreateNewNode : this.app.css.columnCreateEditNode )
  474. }).inject(this.columnCreateNode);
  475. this.columnCreateFormNode = new Element("div", {
  476. "styles": this.app.css.columnCreateFormNode
  477. }).inject(this.columnCreateNode);
  478. var html = "<table width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  479. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left; min-width: 80px; width:25%\">" +
  480. this.app.options.tooltip.column.nameLabel + ":</td>" +
  481. "<td style=\"; text-align: right;\"><input type=\"text\" id=\"createColumnName\" " +
  482. "style=\"width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  483. "height: 26px;\" value=\"" + columnName + "\"/></td></tr>" +
  484. //"<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">" + this.app.options.tooltip.column.aliasLabel + ":</td>" +
  485. //"<td style=\"; text-align: right;\"><input type=\"text\" id=\"createColumnAlias\" " +
  486. //"style=\"width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  487. //"height: 26px;\" value=\"" + alias + "\"/></td></tr>" +
  488. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">" + this.app.options.tooltip.column.descriptionLabel + ":</td>" +
  489. "<td style=\"; text-align: right;\"><input type=\"text\" id=\"createColumnDescription\" " +
  490. "style=\"width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  491. "height: 26px;\" value=\"" + memo + "\"/></td></tr>" +
  492. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">" + this.app.options.tooltip.column.sortLabel + ":</td>" +
  493. "<td style=\"; text-align: right;\"><input type=\"text\" id=\"createColumnSort\" " +
  494. "style=\"width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  495. "height: 26px;\" value=\"" + order + "\"/></td></tr>" +
  496. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">" + this.app.options.tooltip.column.iconLabel + ":</td>" +
  497. "<td style=\"; text-align: right;\"><div id='formIconPreview'></div><div id='formChangeIconAction'></div></td></tr>" +
  498. //"<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.options.tooltip.column.iconLabel+":</td>" +
  499. //"<td style=\"; text-align: right;\"><div " +
  500. //"style=\"height:72px; width:72px;background:url(/x_component_cms_Column/$Main/default/icon/column.png) center center no-repeat \"></div></td></tr>" +
  501. //"<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.options.tooltip.iconLabel+":</td>" +
  502. //"<td style=\"; text-align: right;\"><input type=\"text\" id=\"createColumnType\" " +
  503. //"style=\"width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  504. //"height: 26px;\"/></td></tr>" +
  505. "</table>";
  506. this.columnCreateFormNode.set("html", html);
  507. this.columnCancelActionNode = new Element("div", {
  508. "styles": this.app.css.columnCreateCancelActionNode,
  509. "text": this.app.options.tooltip.column.cancel
  510. }).inject(this.columnCreateFormNode);
  511. this.columnCreateOkActionNode = new Element("div", {
  512. "styles": this.app.css.columnCreateOkActionNode,
  513. "text": this.app.options.tooltip.column.ok
  514. }).inject(this.columnCreateFormNode);
  515. this.columnCancelActionNode.addEvent("click", function (e) {
  516. this.cancelCreateColumn(e);
  517. }.bind(this));
  518. this.columnCreateOkActionNode.addEvent("click", function (e) {
  519. this.okCreateColumn(e);
  520. }.bind(this));
  521. this.iconPreviewNode = this.columnCreateFormNode.getElement("div#formIconPreview");
  522. this.iconActionNode = this.columnCreateFormNode.getElement("div#formChangeIconAction");
  523. this.iconPreviewNode.setStyles({
  524. "height": "72px",
  525. "width": "72px",
  526. "float": "left"
  527. });
  528. if (!this.isNew && this.data.appIcon) {
  529. this.iconPreviewNode.setStyle("background", "url(data:image/png;base64," + this.data.appIcon + ") center center no-repeat");
  530. } else {
  531. this.iconPreviewNode.setStyle("background", "url(" + "/x_component_cms_Column/$Main/default/icon/column.png) center center no-repeat")
  532. }
  533. var changeIconAction = new Element("div", {
  534. "styles": {
  535. "margin-left": "20px",
  536. "float": "left",
  537. "background-color": "#FFF",
  538. "padding": "4px 14px",
  539. "border": "1px solid #999",
  540. "border-radius": "3px",
  541. "margin-top": "10px",
  542. "font-size": "14px",
  543. "color": "#666",
  544. "cursor": "pointer"
  545. },
  546. "text": "更改图标"
  547. }).inject(this.iconActionNode);
  548. changeIconAction.addEvent("click", function () {
  549. this.changeIcon();
  550. }.bind(this));
  551. },
  552. setColumnCreateNodeSize: function () {
  553. var size = this.createContainer.getSize();
  554. var allSize = this.app.content.getSize();
  555. this.columnCreateMarkNode.setStyles({
  556. "width": "" + allSize.x + "px",
  557. "height": "" + allSize.y + "px"
  558. });
  559. this.columnCreateAreaNode.setStyles({
  560. "width": "" + size.x + "px",
  561. "height": "" + size.y + "px"
  562. });
  563. var hY = size.y * 0.8;
  564. var mY = size.y * 0.2 / 2;
  565. this.columnCreateNode.setStyles({
  566. "height": "" + hY + "px",
  567. "margin-top": "" + mY + "px"
  568. });
  569. var iconSize = this.columnCreateNewNode.getSize();
  570. var formHeight = hY * 0.7;
  571. if (formHeight > 250) formHeight = 250;
  572. var formMargin = hY * 0.3 / 2 - iconSize.y;
  573. this.columnCreateFormNode.setStyles({
  574. "height": "" + formHeight + "px",
  575. "margin-top": "" + formMargin + "px"
  576. });
  577. },
  578. cancelCreateColumn: function (e) {
  579. if (this.isNew) {
  580. this.cancelNewColumn(e)
  581. } else {
  582. this.cancelEditColumn(e)
  583. }
  584. },
  585. cancelNewColumn: function (e) {
  586. var _self = this;
  587. if ($("createColumnName").get("value") || $("createColumnAlias").get("value") || $("createColumnDescription").get("value")) {
  588. this.app.confirm("warn", e, this.app.options.tooltip.column.create_cancel_title,
  589. this.app.options.tooltip.column.create_cancel, "320px", "100px", function () {
  590. _self.columnCreateMarkNode.destroy();
  591. _self.columnCreateAreaNode.destroy();
  592. this.close();
  593. }, function () {
  594. this.close();
  595. });
  596. } else {
  597. this.columnCreateMarkNode.destroy();
  598. this.columnCreateAreaNode.destroy();
  599. }
  600. },
  601. cancelEditColumn: function (e) {
  602. this.columnCreateMarkNode.destroy();
  603. this.columnCreateAreaNode.destroy();
  604. },
  605. okCreateColumn: function (e) {
  606. var data = {
  607. "id": (this.data && this.data.id) ? this.data.id : this.app.restActions.getUUID(),
  608. "isNewColumn": this.isNew,
  609. "appName": $("createColumnName").get("value"),
  610. //"appAlias": $("createColumnAlias").get("value"),
  611. "description": $("createColumnDescription").get("value"),
  612. "appInfoSeq": $("createColumnSort").get("value")
  613. };
  614. if( this.data && this.data.appIcon )data.appIcon = this.data.appIcon;
  615. if (data.appName) {
  616. var callback = function ( id ) {
  617. this.app.restActions.getColumn( {id: id}, function (json) {
  618. //保存当前用户为管理员
  619. if (this.isNew) {
  620. var controllerData = {
  621. "objectType": "APPINFO",
  622. "objectId": json.data.id,
  623. "adminUid": layout.desktop.session.user.name,
  624. "adminName": layout.desktop.session.user.name,
  625. "adminLevel": "ADMIN"
  626. };
  627. this.app.restActions.addController(controllerData);
  628. }
  629. if (this.app.noElementNode)this.app.noElementNode.destroy();
  630. var column = new MWF.xApplication.cms.Column.Column(this.app, json.data, {"where": "top"});
  631. column.load();
  632. this.app.columns.push(column);
  633. }.bind(this));
  634. }.bind(this)
  635. this.app.notice(this.isNew ? this.app.options.tooltip.column.createColumnSuccess : this.app.options.tooltip.column.updateColumnSuccess, "success");
  636. this.app.restActions.saveColumn(data, function (json) {
  637. if (json.type == "error") {
  638. this.app.notice(json.message, "error");
  639. } else {
  640. this.columnCreateMarkNode.destroy();
  641. this.columnCreateAreaNode.destroy();
  642. if (!this.isNew)this.node.destroy();
  643. if (this.formData) {
  644. this.saveIcon(json.data.id, callback);
  645. } else {
  646. callback( json.data.id );
  647. }
  648. }
  649. // this.app.processConfig();
  650. }.bind(this), function( errorObj ){
  651. var error = JSON.parse( errorObj.responseText );
  652. this.app.notice( error.message || json.userMessage, "error" );
  653. }.bind(this));
  654. } else {
  655. $("createColumnName").setStyle("border-color", "red");
  656. $("createColumnName").focus();
  657. this.app.notice(this.app.options.tooltip.column.inputName, "error");
  658. }
  659. },
  660. changeIcon: function () {
  661. if (!this.uploadFileAreaNode) {
  662. this.uploadFileAreaNode = new Element("div");
  663. var html = "<input name=\"file\" type=\"file\"/>";
  664. this.uploadFileAreaNode.set("html", html);
  665. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  666. this.fileUploadNode.addEvent("change", function () {
  667. var files = fileNode.files;
  668. if (files.length) {
  669. for (var i = 0; i < files.length; i++) {
  670. var file = files.item(i);
  671. if (!file.type.match('image.*'))continue;
  672. this.file = file;
  673. this.formData = new FormData();
  674. this.formData.append('file', this.file);
  675. if (!window.FileReader) continue;
  676. var reader = new FileReader();
  677. reader.onload = (function (theFile) {
  678. return function (e) {
  679. this.iconPreviewNode.setStyle("background", "");
  680. this.iconPreviewNode.empty();
  681. new Element("img", {
  682. "styles": {
  683. "height": "72px",
  684. "width": "72px"
  685. },
  686. "src": e.target.result
  687. }).inject(this.iconPreviewNode);
  688. }.bind(this);
  689. }.bind(this))(file);
  690. reader.readAsDataURL(file);
  691. }
  692. }
  693. }.bind(this));
  694. }
  695. var fileNode = this.uploadFileAreaNode.getFirst();
  696. fileNode.click();
  697. },
  698. saveIcon: function (id, callback) {
  699. this.app.restActions.updataColumnIcon(id, function () {
  700. this.formData = null;
  701. if (callback)callback( id );
  702. //this.app.restActions.getColumnIcon(this.data.id, function(json){
  703. // if (json.data){
  704. // this.data = json.data;
  705. // if (this.data.icon){
  706. // this.iconPreviewNode.setStyle("background", "url(data:image/png;base64,"+this.data.icon+") center center no-repeat");
  707. // }else{
  708. // this.iconPreviewNode.setStyle("background", "url("+"/x_component_cms_Column/$Main/default/icon/category2.png) center center no-repeat")
  709. // }
  710. // }
  711. //}.bind(this), false)
  712. }.bind(this), null, this.formData, this.file);
  713. }
  714. })