Main.js 31 KB

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