Main.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  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. var middleNode = new Element("div", {
  283. "styles": this.app.css.columnItemMiddleNode
  284. }).inject(itemNode);
  285. var description = ( memo && memo != "") ? memo : this.lp.noDescription;
  286. var descriptionNode = new Element("div", {
  287. "styles": this.app.css.columnItemDescriptionNode,
  288. "text": description,
  289. "title": description
  290. }).inject(middleNode);
  291. var _self = this;
  292. itemNode.addEvents({
  293. "mouseover": function () {
  294. if (!_self.selected) this.setStyles(_self.app.css.columnItemNode_over);
  295. },
  296. "mouseout": function () {
  297. if (!_self.selected) this.setStyles(_self.app.css.columnItemNode);
  298. },
  299. "click": function (e) {
  300. _self.clickColumnNode(_self, this, e)
  301. }
  302. });
  303. var bottomNode = new Element("div", {
  304. "styles": this.app.css.columnItemBottomNode
  305. }).inject(itemNode);
  306. var bottomTitleNode = new Element("div", {
  307. "styles": this.app.css.columnItemCategoryTitleNode,
  308. "text" : this.lp.category
  309. }).inject(bottomNode);
  310. var bottomContentNode_category = new Element("div", {
  311. "styles": this.app.css.columnItemCategoryContentNode
  312. }).inject(bottomNode);
  313. this.app.restActions.listCategory( this.data.id, function ( json ) {
  314. var data = json.data || [];
  315. data.each( function( category ){
  316. var bottomItemNode = new Element("div",{
  317. styles : this.app.css.columnItemBottomItemNode,
  318. text : category.name
  319. }).inject(bottomContentNode_category);
  320. bottomItemNode.addEvents( {
  321. "click": function( ev ){
  322. this.obj.clickColumnNode(this.obj, ev.target, ev, this.data.id);
  323. ev.stopPropagation();
  324. }.bind({ obj : this, data : category }),
  325. "mouseover" : function(){
  326. this.node.setStyles( this.obj.app.css.columnItemBottomItemNode_over );
  327. }.bind({ obj : this, node : bottomItemNode }),
  328. "mouseout" : function(){
  329. this.node.setStyles( this.obj.app.css.columnItemBottomItemNode );
  330. }.bind({ obj : this, node : bottomItemNode })
  331. })
  332. }.bind(this))
  333. }.bind(this) );
  334. var bottomTitleNode = new Element("div", {
  335. "styles": this.app.css.columnItemFormTitleNode,
  336. "text" : this.lp.form
  337. }).inject(bottomNode);
  338. var bottomContentNode_form = new Element("div", {
  339. "styles": this.app.css.columnItemFormContentNode
  340. }).inject(bottomNode);
  341. this.app.restActions.listForm( this.data.id, function ( json ) {
  342. var data = json.data || [];
  343. data.each( function( form ){
  344. var bottomItemNode = new Element("div",{
  345. styles : this.app.css.columnItemBottomItemNode,
  346. text : form.name
  347. }).inject(bottomContentNode_form);
  348. bottomItemNode.addEvents( {
  349. "click": function( ev ){
  350. this.obj.openForm( this.data );
  351. ev.stopPropagation();
  352. }.bind({ obj : this, data : form }),
  353. "mouseover" : function(){
  354. this.node.setStyles( this.obj.app.css.columnItemBottomItemNode_over );
  355. }.bind({ obj : this, node : bottomItemNode }),
  356. "mouseout" : function(){
  357. this.node.setStyles( this.obj.app.css.columnItemBottomItemNode );
  358. }.bind({ obj : this, node : bottomItemNode })
  359. })
  360. }.bind(this))
  361. }.bind(this) );
  362. if ((creator == layout.desktop.session.user.distinguishedName) || MWF.AC.isCMSManager()) {
  363. this.delAdctionNode = new Element("div.delNode", {
  364. "styles": this.app.css.columnItemDelActionNode,
  365. "title": this.lp["delete"]
  366. }).inject(itemNode);
  367. itemNode.addEvents({
  368. "mouseover": function () {
  369. this.delAdctionNode.setStyle("display","");
  370. }.bind(this),
  371. "mouseout": function () {
  372. this.delAdctionNode.setStyle("display","none");
  373. }.bind(this)
  374. });
  375. this.delAdctionNode.addEvent("click", function (e) {
  376. this.deleteColumn(e);
  377. e.stopPropagation();
  378. }.bind(this));
  379. }
  380. if ((creator == layout.desktop.session.user.distinguishedName) || MWF.AC.isCMSManager()) {
  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. if ((creator == layout.desktop.session.user.distinguishedName) || MWF.AC.isCMSManager()) {
  399. this.exportAdctionNode = new Element("div.exportNode", {
  400. "styles": this.app.css.columnItemExportActionNode,
  401. "title": this.lp.export
  402. }).inject(itemNode);
  403. itemNode.addEvents({
  404. "mouseover": function () {
  405. this.exportAdctionNode.setStyle("display","");
  406. }.bind(this),
  407. "mouseout": function () {
  408. this.exportAdctionNode.setStyle("display","none");
  409. }.bind(this)
  410. });
  411. this.exportAdctionNode.addEvent("click", function (e) {
  412. this.export(e);
  413. e.stopPropagation();
  414. }.bind(this));
  415. }
  416. },
  417. export: function(){
  418. //var applicationjson = {
  419. // "application": {},
  420. // "processList": [],
  421. // "formList": [],
  422. // "dictionaryList": [],
  423. // "scriptList": []
  424. //};
  425. //this.app.restActions.getApplication(this.data.name, function(json){
  426. //
  427. //}
  428. MWF.xDesktop.requireApp("cms.Column", "Exporter", function(){
  429. (new MWF.xApplication.cms.Column.Exporter(this.app, this.data)).load();
  430. }.bind(this));
  431. },
  432. edit : function(){
  433. var form = new MWF.xApplication.cms.Column.PopupForm(this.app, this.data, {
  434. title : this.lp.edit
  435. }, {
  436. app : this.app,
  437. container : this.app.content,
  438. lp : this.lp,
  439. css : {},
  440. actions : this.app.restActions
  441. });
  442. form.edit();
  443. },
  444. openForm: function( form ){
  445. layout.desktop.getFormDesignerStyle(function(){
  446. var _self = this;
  447. var options = {
  448. "style": layout.desktop.formDesignerStyle,
  449. "onQueryLoad": function(){
  450. //this.actions = _self.explorer.actions;
  451. this.category = _self;
  452. this.options.id = form.id;
  453. this.column = _self.data;
  454. this.application = _self.data;
  455. }
  456. };
  457. this.app.desktop.openApplication(null, "cms.FormDesigner", options);
  458. }.bind(this));
  459. },
  460. clickColumnNode: function (_self, el, e, currentCategoryId) {
  461. /*
  462. _self.app.columns.each(function( column ){
  463. if( column.selected ){
  464. column.itemNode.setStyles( _self.app.css.columnItemNode );
  465. }
  466. })
  467. this.selected = true;
  468. el.setStyles( _self.app.css.columnItemNode_select );
  469. */
  470. var appId = "cms.ColumnManager" + this.data.id;
  471. if (this.app.desktop.apps[appId]) {
  472. var app = this.app.desktop.apps[appId];
  473. app.setCurrent();
  474. if( currentCategoryId )app.setCategory( currentCategoryId );
  475. } else {
  476. this.app.desktop.openApplication(e, "cms.ColumnManager", {
  477. "currentCategoryId" : currentCategoryId,
  478. "column": this.data,
  479. "appId": appId,
  480. "onQueryLoad": function () {
  481. this.status = {"navi": 0};
  482. }
  483. });
  484. }
  485. },
  486. checkDeleteColumn: function () {
  487. if (this.deleteElements.length) {
  488. if (!this.deleteElementsNode) {
  489. this.deleteElementsNode = new Element("div", {
  490. "styles": this.app.css.deleteElementsNode,
  491. "text": this.lp.deleteElements
  492. }).inject(this.node);
  493. this.deleteElementsNode.position({
  494. relativeTo: this.container,
  495. position: "centerTop",
  496. edge: "centerbottom"
  497. });
  498. this.deleteElementsNode.addEvent("click", function (e) {
  499. this["delete"]();
  500. }.bind(this));
  501. }
  502. } else {
  503. if (this.deleteElementsNode) {
  504. this.deleteElementsNode.destroy();
  505. this.deleteElementsNode = null;
  506. delete this.deleteElementsNode;
  507. }
  508. }
  509. },
  510. deleteColumn: function (e) {
  511. var _self = this;
  512. this.app.confirm("warn", e, this.lp.delete_confirm_title,
  513. this.lp.delete_confirm_content, 320, 100, function () {
  514. _self._deleteElement();
  515. this.close();
  516. }, function( ) {
  517. this.close();
  518. }
  519. )
  520. },
  521. _deleteElement: function (id, success, failure) {
  522. this.app.restActions.removeColumn( id || this.data.id, function () {
  523. this.destroy();
  524. if (success) success();
  525. }.bind(this), function( error ){
  526. var errorObj = JSON.parse( error.responseText );
  527. this.app.notice(errorObj.message , "error");
  528. if(failure)failure();
  529. }.bind(this));
  530. },
  531. destroy: function () {
  532. this.node.destroy();
  533. MWF.release(this);
  534. delete this;
  535. }
  536. });
  537. MWF.xApplication.cms.Column.PopupForm = new Class({
  538. Extends: MPopupForm,
  539. Implements: [Options, Events],
  540. options: {
  541. "style": "blue",
  542. "width": "650",
  543. "height": "400",
  544. "hasTop": true,
  545. "hasIcon": false,
  546. "hasTopContent" : true,
  547. "hasBottom": true,
  548. //"title": MWF.xApplication.cms.Index.LP.createDocument,
  549. "draggable": true,
  550. "closeAction": true
  551. },
  552. _createTableContent: function () {
  553. if (!this.isNew) {
  554. var columnName = this.data.appName;
  555. var alias = this.data.appAlias;
  556. var memo = this.data.description;
  557. var order = this.data.appInfoSeq;
  558. var creator = this.data.creatorUid;
  559. var createTime = this.data.createTime;
  560. //var icon = this.data.appIcon;
  561. //if( !icon || icon == "")icon = this.app.defaultColumnIcon;
  562. } else {
  563. var columnName = "";
  564. var alias = "";
  565. var memo = "";
  566. var order = "";
  567. var creator = "";
  568. var icon = "";
  569. var createTime = "";
  570. }
  571. var html = "<table width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  572. "<tr><td style=\"font-size:16px; height: 40px; line-height: 40px; text-align: left; min-width: 60px; width:20%\">" +
  573. this.lp.nameLabel + ":</td>" +
  574. "<td style=\"; text-align: right;\"><input type=\"text\" id=\"createColumnName\" " +
  575. "style=\"width: 95%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  576. "height: 26px;\" value=\"" + columnName + "\"/></td></tr>" +
  577. "<tr><td style=\"font-size:16px; height: 40px; line-height: 40px; text-align: left\">" + this.lp.descriptionLabel + ":</td>" +
  578. "<td style=\"; text-align: right;\"><input type=\"text\" id=\"createColumnDescription\" " +
  579. "style=\"width: 95%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  580. "height: 26px;\" value=\"" + memo + "\"/></td></tr>" +
  581. "<tr><td style=\"font-size:16px; height: 40px; line-height: 40px; text-align: left\">" + this.lp.sortLabel + ":</td>" +
  582. "<td style=\"; text-align: right;\"><input type=\"text\" id=\"createColumnSort\" " +
  583. "style=\"width: 95%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  584. "height: 26px;\" value=\"" + order + "\"/></td></tr>" +
  585. "<tr><td style=\"font-size:16px; height: 40px; line-height: 40px; text-align: left\">" + this.lp.iconLabel + ":</td>" +
  586. "<td style=\"; text-align: right;\"><div id='formIconPreview'></div><div id='formChangeIconAction'></div></td></tr>" +
  587. "</table>";
  588. this.formTableArea.set("html", html);
  589. this.setContent();
  590. this.setIconContent();
  591. },
  592. _setCustom: function(){
  593. this.formTableContainer.setStyles({
  594. "padding-top" : "15px",
  595. "width" : "470px"
  596. });
  597. this.formBottomNode.setStyles({
  598. "padding-right" : "170px",
  599. "padding-bottom" : "50px"
  600. });
  601. },
  602. setContent: function(){
  603. this.nameInput = this.formTableArea.getElementById("createColumnName");
  604. this.descriptionInput = this.formTableArea.getElementById("createColumnDescription");
  605. this.sortInput = this.formTableArea.getElementById("createColumnSort");
  606. },
  607. setIconContent: function(){
  608. this.iconPreviewNode = this.formTableArea.getElement("div#formIconPreview");
  609. this.iconActionNode = this.formTableArea.getElement("div#formChangeIconAction");
  610. this.iconPreviewNode.setStyles({
  611. "margin-left" : "20px",
  612. "margin-top" : "10px",
  613. "height": "72px",
  614. "width": "72px",
  615. "float": "left"
  616. });
  617. if (!this.isNew && this.data.appIcon) {
  618. this.iconPreviewNode.setStyle("background", "url(data:image/png;base64," + this.data.appIcon + ") center center no-repeat");
  619. } else {
  620. this.iconPreviewNode.setStyle("background", "url(" + "/x_component_cms_Column/$Main/default/icon/column.png) center center no-repeat")
  621. }
  622. var changeIconAction = new Element("div", {
  623. "styles": {
  624. "margin-left": "20px",
  625. "float": "left",
  626. "background-color": "#FFF",
  627. "padding": "4px 14px",
  628. "border": "1px solid #999",
  629. "border-radius": "3px",
  630. "margin-top": "25px",
  631. "font-size": "14px",
  632. "color": "#666",
  633. "cursor": "pointer"
  634. },
  635. "text": "更改图标"
  636. }).inject(this.iconActionNode);
  637. changeIconAction.addEvent("click", function () {
  638. this.changeIcon();
  639. }.bind(this));
  640. },
  641. cancel: function (e) {
  642. this.fireEvent("queryCancel");
  643. if (this.isNew) {
  644. this.cancelNewColumn(e)
  645. } else {
  646. this.close();
  647. }
  648. this.fireEvent("postCancel");
  649. },
  650. cancelNewColumn: function (e) {
  651. var _self = this;
  652. if (this.nameInput.get("value") || this.descriptionInput.get("value")) {
  653. this.app.confirm("warn", e, this.lp.create_cancel_title,
  654. this.lp.create_cancel, 320, 100, function () {
  655. _self.close();
  656. this.close();
  657. }, function () {
  658. this.close();
  659. });
  660. } else {
  661. _self.close();
  662. }
  663. },
  664. ok: function (e) {
  665. this.fireEvent("queryOk");
  666. var data = {
  667. "id": (this.data && this.data.id) ? this.data.id : this.app.restActions.getUUID(),
  668. "isNewColumn": this.isNew,
  669. "appName": this.nameInput.get("value"),
  670. "description": this.descriptionInput.get("value"),
  671. "appInfoSeq": this.sortInput.get("value")
  672. };
  673. if( this.data && this.data.appIcon )data.appIcon = this.data.appIcon;
  674. if (!data.appName) {
  675. this.app.notice( this.lp.inputName );
  676. return;
  677. }else{
  678. var callback = function ( id ) {
  679. this.app.restActions.getColumn( id, function (json) {
  680. //保存当前用户为管理员
  681. if (this.isNew) {
  682. //var controllerData = {
  683. // "objectType": "APPINFO",
  684. // "objectId": json.data.id,
  685. // "adminUid": layout.desktop.session.user.distinguishedName,
  686. // "adminName": layout.desktop.session.user.distinguishedName,
  687. // "adminLevel": "ADMIN"
  688. //};
  689. //this.app.restActions.addController(controllerData);
  690. var data = {
  691. personList : [ layout.desktop.session.user.distinguishedName || "xadmin" ],
  692. unitList : [],
  693. groupList : []
  694. };
  695. this.app.restActions.saveAppInfoManager(json.data.id, data, function (js) {
  696. }.bind(this), null, false);
  697. }
  698. if (this.app.noElementNode)this.app.noElementNode.destroy();
  699. if( this.formMaskNode )this.formMaskNode.destroy();
  700. this.formAreaNode.destroy();
  701. if( this.app )this.app.notice(this.isNew ? this.lp.createColumnSuccess : this.lp.updateColumnSuccess, "success");
  702. if( this.isNew ){
  703. var column = new MWF.xApplication.cms.Column.Column(this.app, json.data, {"where": "top"});
  704. column.load();
  705. this.app.columns.push(column);
  706. }else{
  707. this.app.reload();
  708. }
  709. this.fireEvent("postOk");
  710. }.bind(this));
  711. }.bind(this);
  712. this.app.restActions.saveColumn(data, function (json) {
  713. if (json.type == "error") {
  714. this.app.notice(json.message, "error");
  715. } else {
  716. if (this.formData) {
  717. this.saveIcon(json.data.id, callback);
  718. } else {
  719. callback( json.data.id );
  720. }
  721. }
  722. // this.app.processConfig();
  723. }.bind(this), function( errorObj ){
  724. var error = JSON.parse( errorObj.responseText );
  725. this.app.notice( error.message || json.userMessage, "error" );
  726. }.bind(this));
  727. }
  728. },
  729. changeIcon: function () {
  730. if (!this.uploadFileAreaNode) {
  731. this.uploadFileAreaNode = new Element("div");
  732. var html = "<input name=\"file\" type=\"file\"/>";
  733. this.uploadFileAreaNode.set("html", html);
  734. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  735. this.fileUploadNode.addEvent("change", function () {
  736. var files = fileNode.files;
  737. if (files.length) {
  738. for (var i = 0; i < files.length; i++) {
  739. var file = files.item(i);
  740. if (!file.type.match('image.*'))continue;
  741. this.file = file;
  742. this.formData = new FormData();
  743. this.formData.append('file', this.file);
  744. if (!window.FileReader) continue;
  745. var reader = new FileReader();
  746. reader.onload = (function (theFile) {
  747. return function (e) {
  748. this.iconPreviewNode.setStyle("background", "");
  749. this.iconPreviewNode.empty();
  750. new Element("img", {
  751. "styles": {
  752. "height": "72px",
  753. "width": "72px"
  754. },
  755. "src": e.target.result
  756. }).inject(this.iconPreviewNode);
  757. }.bind(this);
  758. }.bind(this))(file);
  759. reader.readAsDataURL(file);
  760. }
  761. }
  762. }.bind(this));
  763. }
  764. var fileNode = this.uploadFileAreaNode.getFirst();
  765. fileNode.click();
  766. },
  767. saveIcon: function (id, callback) {
  768. this.app.restActions.updataColumnIcon(id, function () {
  769. this.formData = null;
  770. if (callback)callback( id );
  771. }.bind(this), null, this.formData, this.file);
  772. }
  773. });