Main.js 33 KB

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