Main.js 41 KB

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