Creater.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. MWF.require("MWF.widget.Mask", null, false);
  2. MWF.xApplication.cms = MWF.xApplication.cms || {};
  3. MWF.xApplication.cms.Index = MWF.xApplication.cms.Index || {};
  4. MWF.xApplication.cms.Index.Creater = new Class({
  5. Extends: MWF.widget.Common,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default"
  9. },
  10. initialize: function(app, columnData, view, options){
  11. this.setOptions(options);
  12. this.path = "../x_component_cms_Index/$Creater/";
  13. this.cssPath = "../x_component_cms_Index/$Creater/"+this.options.style+"/css.wcss";
  14. this._loadCss();
  15. this.app = app;
  16. this.view = view;
  17. this.columnData = columnData;
  18. MWF.xDesktop.requireApp("cms.Index", "$Creater."+MWF.language, null, false);
  19. this.lp = MWF.xApplication.cms.Index.Creater.lp;
  20. },
  21. load: function(){
  22. if (!this.startDocumentAreaNode){
  23. this.createStartDocumentArea();
  24. }
  25. this.startDocumentAreaNode.fade("0.95");
  26. },
  27. closeStartDocumentArea: function(){
  28. //if (this.startDocumentAreaNode) this.startDocumentTween.start("left", "0px", "-400px");
  29. if (this.startDocumentAreaNode) this.startDocumentAreaNode.fade("out");
  30. },
  31. createStartDocumentArea: function(){
  32. this.createStartDocumentAreaNode();
  33. this.createStartDocumentCloseNode();
  34. this.createStartDocumentScrollNode();
  35. if( this.columnData ){
  36. if(!this.columnData.name)this.columnData.name = this.columnData.appName;
  37. new MWF.xApplication.cms.Index.Creater.Column(this.columnData, this.app, this, this.startDocumentContentNode, true );
  38. }else{
  39. this.listColumns();
  40. }
  41. this.setResizeStartDocumentAreaHeight();
  42. this.app.addEvent("resize", this.setResizeStartDocumentAreaHeight.bind(this));
  43. },
  44. createStartDocumentAreaNode: function(){
  45. this.startDocumentAreaNode = new Element("div", {"styles": this.css.startDocumentAreaNode}).inject(this.app.content);
  46. this.startDocumentAreaNode.addEvent("click", function(e){
  47. this.closeStartDocumentArea();
  48. }.bind(this));
  49. },
  50. createStartDocumentCloseNode: function(){
  51. this.startDocumentTopNode = new Element("div", {"styles": this.css.startDocumentTopNode}).inject(this.startDocumentAreaNode);
  52. this.startDocumentCloseNode = new Element("div", {"styles": this.css.startDocumentCloseNode}).inject(this.startDocumentTopNode);
  53. this.startDocumentCloseNode.addEvent("click", function(e){
  54. this.closeStartDocumentArea();
  55. }.bind(this));
  56. },
  57. createStartDocumentScrollNode: function(){
  58. this.startDocumentScrollNode = new Element("div", {"styles": this.css.startDocumentScrollNode}).inject(this.startDocumentAreaNode);
  59. MWF.require("MWF.widget.ScrollBar", function(){
  60. new MWF.widget.ScrollBar(this.startDocumentScrollNode, {
  61. "style":"xApp_taskcenter", "where": "after", "distance": 30, "friction": 4, "axis": {"x": false, "y": true}
  62. });
  63. }.bind(this));
  64. this.startDocumentContentNode = new Element("div", {"styles": this.css.startDocumentContentNode}).inject(this.startDocumentScrollNode);
  65. },
  66. listColumns: function(){
  67. this.getAction(function(){
  68. this.action.listColumnByPublish(function(json){
  69. json.data.each(function(column){
  70. if(!column.name)column.name = column.appName;
  71. new MWF.xApplication.cms.Index.Creater.Column(column, this.app, this, this.startDocumentContentNode);
  72. }.bind(this));
  73. }.bind(this));
  74. }.bind(this));
  75. },
  76. getAction: function(callback){
  77. if (!this.action){
  78. //MWF.xDesktop.requireApp("cms.Index", "Actions.RestActions", function(){
  79. this.action = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.Index.Actions.RestActions();
  80. if (callback) callback();
  81. //}.bind(this));
  82. }else{
  83. if (callback) callback();
  84. }
  85. },
  86. setResizeStartDocumentAreaHeight: function(){
  87. var size = this.app.content.getSize();
  88. if (this.startDocumentAreaNode){
  89. var topSize = this.startDocumentCloseNode.getSize();
  90. var y = size.y-topSize.y-80;
  91. var x = size.x - 110;
  92. var areay = size.y-60;
  93. var areax = size.x-90;
  94. this.startDocumentScrollNode.setStyle("height", ""+y+"px");
  95. this.startDocumentScrollNode.setStyle("width", ""+x+"px");
  96. this.startDocumentAreaNode.setStyle("height", ""+areay+"px");
  97. this.startDocumentAreaNode.setStyle("width", ""+areax+"px");
  98. }
  99. }
  100. });
  101. MWF.xApplication.cms.Index.Creater.Column = new Class({
  102. initialize: function(data, app, creater, container, needGetCategorys ){
  103. this.bgColors = ["#30afdc", "#e9573e", "#8dc153", "#9d4a9c", "#ab8465", "#959801", "#434343", "#ffb400", "#9e7698", "#00a489"];
  104. this.data = data;
  105. this.app = app;
  106. this.creater = creater;
  107. this.container = container;
  108. this.css = this.creater.css;
  109. this.needGetCategorys = needGetCategorys;
  110. this.load();
  111. },
  112. load: function(){
  113. this.node = new Element("div", {"styles": this.css.columnNode}).inject(this.container);
  114. this.topNode = new Element("div", {"styles": this.css.columnTopNode}).inject(this.node);
  115. // this.topNode.setStyle("background-color", this.bgColors[(Math.random()*10).toInt()]);
  116. //this.iconNode = new Element("div", {"styles": this.css.columnIconNode}).inject(this.topNode);
  117. //if (this.data.appIcon){
  118. // this.iconNode.setStyle("background-image", "url(data:image/png;base64,"+this.data.appIcon+")");
  119. //}else{
  120. // this.iconNode.setStyle("background-image", "url("+this.creater.path+this.creater.options.style+"/column.png)")
  121. //}
  122. var iconAreaNode = this.iconAreaNode = new Element("div",{
  123. "styles" : this.css.columnIconAreaNode
  124. }).inject(this.topNode);
  125. var iconNode = this.iconNode = new Element("img",{
  126. "styles" : this.css.columnIconNode
  127. }).inject(iconAreaNode);
  128. if (this.data.appIcon){
  129. this.iconNode.set("src", "data:image/png;base64,"+this.data.appIcon+"");
  130. }else{
  131. this.iconNode.set("src", this.creater.path+this.creater.options.style+"/column.png")
  132. }
  133. this.textNode = new Element("div", {"styles": this.css.columnTextNode}).inject(this.topNode);
  134. this.textNode.set("text", this.data.name);
  135. this.childNode = new Element("div", {"styles": this.css.columnChildNode}).inject(this.node);
  136. this.loadChild();
  137. },
  138. loadChild: function(){
  139. if( this.needGetCategorys ){
  140. this.creater.getAction(function(){
  141. this.creater.action.listCategoryByPublisher(this.data.id,function(json){
  142. if (json.data.length){
  143. json.data.each(function(category){
  144. new MWF.xApplication.cms.Index.Creater.Category(category, this, this.childNode);
  145. }.bind(this));
  146. }else{
  147. this.node.setStyle("display", "none");
  148. }
  149. }.bind(this), null, this.data.id)
  150. }.bind(this))
  151. }else{
  152. if( this.data.wrapOutCategoryList && this.data.wrapOutCategoryList.length ){
  153. this.data.wrapOutCategoryList.each(function(category){
  154. new MWF.xApplication.cms.Index.Creater.Category(category, this, this.childNode);
  155. }.bind(this));
  156. }else{
  157. this.node.setStyle("display", "none");
  158. }
  159. }
  160. }
  161. });
  162. MWF.xApplication.cms.Index.Creater.Category = new Class({
  163. initialize: function(data, column, container){
  164. this.data = data;
  165. this.column = column;
  166. this.app = this.column.app;
  167. this.creater = this.column.creater;
  168. this.container = container;
  169. this.css = this.creater.css;
  170. this.load();
  171. },
  172. load: function(){
  173. if( !this.data.name )this.data.name = this.data.categoryName;
  174. this.node = new Element("div.categoryItem", {"styles": this.css.startCategoryNode}).inject(this.container);
  175. this.iconNode = new Element("div", {"styles": this.css.categoryIconNode}).inject(this.node);
  176. this.textNode = new Element("div", {"styles": this.css.categoryTextNode}).inject(this.node);
  177. this.textNode.set({
  178. "text": this.data.categoryName
  179. });
  180. var _self = this;
  181. this.node.addEvents({
  182. "mouseover": function(e){this.node.setStyles(this.css.startCategoryNode_over);}.bind(this),
  183. "mouseout": function(e){this.node.setStyles(this.css.startCategoryNode_out);}.bind(this),
  184. "click": function(e){
  185. this.createDocument(e);
  186. }.bind(this)
  187. });
  188. },
  189. //createDocument: function( e ){
  190. // var fielter = {
  191. // "categoryIdList": [this.data.id ],
  192. // "creatorList": [layout.desktop.session.user.name]
  193. // };
  194. // this.creater.getAction(function(){
  195. // this.creater.action.listDraftNext("(0)", 1, fielter, function(json){
  196. // if( json.data.length > 0 ){
  197. // this._openDocument(json.data[0].id);
  198. // }else{
  199. // this._createDocument();
  200. // }
  201. // }.bind(this));
  202. // }.bind(this))
  203. //},
  204. createDocument : function(){
  205. this.creater.closeStartDocumentArea();
  206. if( !this.data.formId || this.data.formId=="" ){
  207. this.app.notice(this.creater.lp.noFormSelected, "error");
  208. return;
  209. }
  210. MWF.xDesktop.requireApp("cms.Index", "Starter", function(){
  211. var starter = new MWF.xApplication.cms.Index.Starter(this.column.data, this.data, this.app, {
  212. //"onStarted": function(data, title, categoryName){
  213. // this.afterStart(data, title, categoryName);
  214. //}.bind(this)
  215. onPostPublish : function(){
  216. if(this.creater.view )this.creater.view.reload();
  217. }.bind(this)
  218. });
  219. starter.load();
  220. }.bind(this));
  221. }
  222. //_openDocument: function(id,el){
  223. // var _self = this;
  224. //
  225. // var appId = "cms.Document"+id;
  226. // if (_self.app.desktop.apps[appId]){
  227. // _self.app.desktop.apps[appId].setCurrent();
  228. // }else {
  229. // var options = {
  230. // "readonly" :false,
  231. // "documentId": id,
  232. // "appId": appId,
  233. // "postPublish" : function(){
  234. // if(_self.creater.view )_self.creater.view.reload();
  235. // }
  236. // };
  237. // this.app.desktop.openApplication(el, "cms.Document", options);
  238. // }
  239. //},
  240. //afterStart : function(data, title, categoryName){
  241. // var _self = this;
  242. // var appId = "cms.Document"+data.id;
  243. // if (_self.app.desktop.apps[appId]){
  244. // _self.app.desktop.apps[appId].setCurrent();
  245. // }else {
  246. // var options = {
  247. // "readonly" :false,
  248. // "documentId": data.id,
  249. // "appId": appId,
  250. // "postPublish" : function(){
  251. // if(_self.creater.view )_self.creater.view.reload();
  252. // }
  253. // };
  254. // this.app.desktop.openApplication(null, "cms.Document", options);
  255. // }
  256. //}
  257. });