Main.js 41 KB

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