Main.js 40 KB

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