Main.js 39 KB

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