Main.js 41 KB

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