ViewExplorer.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. MWF.xDesktop.requireApp("cms.ColumnManager", "Explorer", null, false);
  2. MWF.xApplication.cms.ColumnManager.ViewExplorer = new Class({
  3. Extends: MWF.xApplication.cms.ColumnManager.Explorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "style" : "default",
  7. "create": MWF.CMSCM.LP.view.create,
  8. "search": MWF.CMSCM.LP.view.search,
  9. "searchText": MWF.CMSCM.LP.view.searchText,
  10. "noElement": MWF.CMSCM.LP.view.noViewNoticeText
  11. },
  12. initialize: function(node, actions, options){
  13. this.setOptions(options);
  14. this.setTooltip();
  15. this.path = "/x_component_cms_ColumnManager/$ViewExplorer/";
  16. this.cssPath = "/x_component_cms_ColumnManager/$ViewExplorer/"+this.options.style+"/css.wcss";
  17. this._loadCss();
  18. this.actions = actions;
  19. this.node = $(node);
  20. this.initData();
  21. },
  22. setContentSize: function(){
  23. var toolbarSize = this.toolbarNode ? this.toolbarNode.getSize() : { x :0 , y :0 };
  24. var nodeSize = this.node.getSize();
  25. var pt = this.elementContentNode.getStyle("padding-top").toFloat();
  26. var pb = this.elementContentNode.getStyle("padding-bottom").toFloat();
  27. var height = nodeSize.y-toolbarSize.y-pt-pb;
  28. this.elementContentNode.setStyle("height", ""+height+"px");
  29. if (this.options.noCreate) this.createElementNode.destroy();
  30. },
  31. showDeleteAction: function(){
  32. if (!this.deleteItemsAction){
  33. this.deleteItemsAction = new Element("div", {
  34. "styles": this.css.deleteItemsAction,
  35. "text": this.app.lp.deleteItems
  36. }).inject(this.node);
  37. this.deleteItemsAction.fade("in");
  38. this.deleteItemsAction.position({
  39. relativeTo: this.elementContentListNode,
  40. position: 'centerTop',
  41. edge: 'centerTop'
  42. });
  43. this.deleteItemsAction.addEvent("click", function(){
  44. var _self = this;
  45. this.app.confirm("warn", this.deleteItemsAction, MWF.CMSCM.LP.deleteElementTitle, MWF.CMSCM.LP.deleteElement, 300, 120, function(){
  46. _self.deleteItems();
  47. this.close();
  48. }, function(){
  49. this.close();
  50. });
  51. }.bind(this));
  52. }
  53. },
  54. //_createElement: function(e){
  55. // var _self = this;
  56. // var options = {
  57. // "onQueryLoad": function(){
  58. // this.actions = _self.app.restActions;
  59. // this.application = _self.app.options.column;
  60. // this.column = _self.app.options.column;
  61. // }
  62. // };
  63. // this.app.desktop.openApplication(e, "cms.ViewDesigner", options);
  64. //},
  65. _createElement: function(e){
  66. var _self = this;
  67. var createView = function(e, form){
  68. layout.desktop.getFormDesignerStyle(function(){
  69. var options = {
  70. "style": layout.desktop.formDesignerStyle,
  71. "onQueryLoad": function(){
  72. this.actions = _self.app.restActions;
  73. this.column = _self.app.options.column;
  74. this.application = _self.app.options.column;
  75. this.relativeForm = form;
  76. },
  77. "onPostSave" : function(){
  78. _self.reload();
  79. }
  80. };
  81. layout.desktop.openApplication(e, "cms.ViewDesigner", options);
  82. }.bind(this));
  83. }
  84. var selectFormMaskNode = new Element("div", {"styles": this.css.selectFormMaskNode}).inject(this.app.content);
  85. var selectFormAreaNode = new Element("div", {"styles": this.css.selectFormTemplateAreaNode}).inject(this.app.content);
  86. selectFormAreaNode.fade("in");
  87. var selectFormTitleNode = new Element("div",{"styles":this.css.selectFormTitleNode,"text":this.app.lp.view.selectRelativeForm}).inject(selectFormAreaNode);
  88. var selectFormScrollNode = new Element("div", {"styles": this.css.selectFormScrollNode}).inject(selectFormAreaNode);
  89. var selectFormContentNode = new Element("div", {"styles": this.css.selectFormContentNode}).inject(selectFormScrollNode);
  90. MWF.require("MWF.widget.ScrollBar", function(){
  91. new MWF.widget.ScrollBar(selectFormScrollNode, {"indent": false});
  92. }.bind(this));
  93. var _self = this;
  94. this.app.restActions.listForm(this.app.options.column.id, function(json){
  95. json.data.each(function(form){
  96. var formNode = new Element("div", {
  97. "styles": this.css.formNode
  98. }).inject(selectFormContentNode);
  99. var x = "process_icon_" + (Math.random()*33).toInt() + ".png";
  100. var iconUrl = this.path+this.options.style+"/processIcon/"+x;
  101. var formIconNode = new Element("div", {
  102. "styles": this.css.formIconNode
  103. }).inject(formNode);
  104. formIconNode.setStyle("background", "url("+iconUrl+") center center no-repeat");
  105. new Element("div", {
  106. "styles": this.css.formTitleNode,
  107. "text": form.name
  108. }).inject(formNode);
  109. new Element("div", {
  110. "styles": this.css.formDescriptionNode,
  111. "text": form.description || "",
  112. "title": form.description || ""
  113. }).inject(formNode);
  114. new Element("div", {
  115. "styles": this.css.formDateNode,
  116. "text": (form.updateTime || "")
  117. }).inject(formNode);
  118. formNode.store("form", {"name":form.name, "id":form.id});
  119. formNode.addEvents({
  120. "mouseover": function(){this.setStyles(_self.css.formNode_over)},
  121. "mouseout": function(){this.setStyles(_self.css.formNode)},
  122. "mousedown": function(){this.setStyles(_self.css.formNode_down)},
  123. "mouseup": function(){this.setStyles(_self.css.formNode_over)},
  124. "click": function(e){
  125. createView(e, this.retrieve("form"));
  126. selectFormAreaNode.destroy();
  127. selectFormMaskNode.destroy();
  128. }
  129. });
  130. }.bind(this))
  131. }.bind(this));
  132. selectFormMaskNode.addEvent("click", function(){
  133. selectFormAreaNode.destroy();
  134. selectFormMaskNode.destroy();
  135. });
  136. var size = this.app.content.getSize();
  137. var y = (size.y - 262)/2;
  138. var x = (size.x - 828)/2;
  139. if (y<0) y=0;
  140. if (x<0) x=0;
  141. selectFormAreaNode.setStyles({
  142. "top": ""+y+"px",
  143. "left": ""+x+"px"
  144. });
  145. },
  146. _loadItemDataList: function(callback){
  147. this.actions.listView(this.app.options.column.id,callback);
  148. },
  149. _getItemObject: function(item){
  150. return new MWF.xApplication.cms.ColumnManager.ViewExplorer.View(this, item)
  151. },
  152. setTooltip: function(){
  153. this.options.tooltip = {
  154. "create": MWF.CMSCM.LP.view.create,
  155. "search": MWF.CMSCM.LP.view.search,
  156. "searchText": MWF.CMSCM.LP.view.searchText,
  157. "noElement": MWF.CMSCM.LP.view.noViewNoticeText
  158. };
  159. },
  160. loadElementList: function(){
  161. this._loadItemDataList(function(json){
  162. if (json.data.length){
  163. json.data.each(function(item){
  164. var itemObj = this._getItemObject(item);
  165. itemObj.load();
  166. this.itemObject[ item.id ] = itemObj;
  167. this.itemArray.push( itemObj );
  168. }.bind(this));
  169. }else{
  170. var noElementNode = new Element("div", {
  171. "styles": this.css.noElementNode,
  172. "text": (this.options.noCreate) ? MWF.CMSCM.LP.view.noViewNoCreateNoticeText : this.options.tooltip.noElement
  173. }).inject(this.elementContentListNode);
  174. if (!this.options.noCreate){
  175. noElementNode.addEvent("click", function(e){
  176. this._createElement(e);
  177. }.bind(this));
  178. }
  179. }
  180. }.bind(this));
  181. },
  182. deleteItems: function(){
  183. while (this.deleteMarkItems.length){
  184. var item = this.deleteMarkItems.shift();
  185. if (this.deleteMarkItems.length){
  186. item.deleteView();
  187. }else{
  188. item.deleteView(function(){
  189. // this.reloadItems();
  190. this.hideDeleteAction();
  191. this.reload();
  192. }.bind(this));
  193. }
  194. }
  195. }
  196. });
  197. MWF.xApplication.cms.ColumnManager.ViewExplorer.View = new Class({
  198. Extends: MWF.xApplication.cms.ColumnManager.Explorer.Item,
  199. load: function(){
  200. this.node = new Element("div", {
  201. "styles": this.explorer.css.itemNode,
  202. "events": {
  203. "mouseover": function(){if (this.deleteActionNode) this.deleteActionNode.fade("in");}.bind(this),
  204. "mouseout": function(){if (this.deleteActionNode) this.deleteActionNode.fade("out");}.bind(this)
  205. }
  206. }).inject(this.container);
  207. if (this.data.name.icon) this.icon = this.data.name.icon;
  208. var iconUrl = this.explorer.path+""+this.explorer.options.style+"/processIcon/"+this.icon;
  209. var itemIconNode = new Element("div", {
  210. "styles": this.explorer.css.itemIconNode
  211. }).inject(this.node);
  212. itemIconNode.setStyle("background", "url("+iconUrl+") center center no-repeat");
  213. //new Element("img", {
  214. // "src": iconUrl, "border": "0"
  215. //}).inject(itemIconNode);
  216. itemIconNode.makeLnk({
  217. "par": this._getLnkPar()
  218. });
  219. if (!this.explorer.options.noDelete){
  220. this.deleteActionNode = new Element("div", {
  221. "styles": this.explorer.css.deleteActionNode
  222. }).inject(this.node);
  223. this.deleteActionNode.addEvent("click", function(e){
  224. this.deleteItem(e);
  225. }.bind(this));
  226. }
  227. var inforNode = new Element("div", {
  228. "styles": this.explorer.css.itemInforNode
  229. }).inject(this.node);
  230. var inforBaseNode = new Element("div", {
  231. "styles": this.explorer.css.itemInforBaseNode
  232. }).inject(inforNode);
  233. new Element("div", {
  234. "styles": this.explorer.css.itemTextTitleNode,
  235. "text": this.data.name,
  236. "title": this.data.name,
  237. "events": {
  238. "click": function(e){this._open(e);e.stopPropagation();}.bind(this)
  239. }
  240. }).inject(inforBaseNode);
  241. new Element("div", {
  242. "styles": this.explorer.css.itemTextAliasNode,
  243. "text": this.data.alias,
  244. "title": this.data.alias
  245. }).inject(inforBaseNode);
  246. new Element("div", {
  247. "styles": this.explorer.css.itemTextDateNode,
  248. "text": (this.data.updateTime || "")
  249. }).inject(inforBaseNode);
  250. new Element("div", {
  251. "styles": this.explorer.css.itemTextDescriptionNode,
  252. "text": this.data.description || "",
  253. "title": this.data.description || ""
  254. }).inject(inforNode);
  255. this._customNodes();
  256. this._isNew();
  257. },
  258. _customNodes: function(){},
  259. _open: function(e){
  260. var _self = this;
  261. var options = {
  262. "onQueryLoad": function(){
  263. this.actions = _self.explorer.actions;
  264. this.category = _self;
  265. this.options.id = _self.data.id;
  266. this.column = _self.explorer.app.options.column;
  267. this.application = _self.explorer.app.options.column;
  268. this.options.noModifyName = _self.explorer.options.noModifyName;
  269. this.options.readMode = _self.explorer.options.readMode,
  270. this.options.formId = _self.data.formId;
  271. }
  272. };
  273. this.explorer.app.desktop.openApplication(e, "cms.ViewDesigner", options);
  274. },
  275. _getIcon: function(){
  276. var x = (Math.random()*33).toInt();
  277. return "process_icon_"+x+".png";
  278. },
  279. _getLnkPar: function(){
  280. return {
  281. "icon": this.explorer.path+this.explorer.options.style+"/viewIcon/lnk.png",
  282. "title": this.data.name,
  283. "par": "cms.ViewDesigner#{\"id\": \""+this.data.id+"\"}"
  284. };
  285. },
  286. // deleteItem: function(e){
  287. // var _self = this;
  288. // this.explorer.app.confirm("info", e, this.explorer.app.lp.form.deleteFormTitle, this.explorer.app.lp.form.deleteForm, 320, 110, function(){
  289. // _self.deleteForm();
  290. // this.close();
  291. // },function(){
  292. // this.close();
  293. // });
  294. // },
  295. deleteView: function(callback){
  296. this.explorer.app.restActions.deleteView(this.data.id, function(){
  297. this.node.destroy();
  298. if (callback) callback();
  299. }.bind(this));
  300. }
  301. });