Starter.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. MWF.require("MWF.widget.Mask", null, false);
  2. MWF.xApplication.cms = MWF.xApplication.cms || {};
  3. MWF.xApplication.cms.Explorer = MWF.xApplication.cms.Explorer || {};
  4. MWF.xApplication.cms.Explorer.Starter = new Class({
  5. Extends: MWF.widget.Common,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default"
  9. },
  10. initialize: function(columnData, categoryData, app, options){
  11. this.setOptions(options);
  12. this.path = "/x_component_cms_Explorer/$Starter/";
  13. this.cssPath = "/x_component_cms_Explorer/$Starter/"+this.options.style+"/css.wcss";
  14. this._loadCss();
  15. MWF.xDesktop.requireApp("cms.Explorer", "$Starter."+MWF.language, null, false);
  16. this.lp = MWF.xApplication.cms.Explorer.Starter.lp;
  17. this.columnData = columnData;
  18. this.categoryData = categoryData;
  19. this.app = app;
  20. },
  21. load: function(){
  22. this.createMarkNode();
  23. this.createAreaNode();
  24. this.createStartNode();
  25. this.areaNode.inject(this.markNode, "after");
  26. this.areaNode.fade("in");
  27. $("form_startSubject").focus();
  28. this.setStartNodeSize();
  29. this.setStartNodeSizeFun = this.setStartNodeSize.bind(this);
  30. this.app.addEvent("resize", this.setStartNodeSizeFun);
  31. },
  32. createMarkNode: function(){
  33. this.markNode = new Element("div#mark", {
  34. "styles": this.css.markNode,
  35. "events": {
  36. "mouseover": function(e){e.stopPropagation();},
  37. "mouseout": function(e){e.stopPropagation();}
  38. }
  39. }).inject(this.app.content);
  40. },
  41. createAreaNode: function(){
  42. this.areaNode = new Element("div#area", {
  43. "styles": this.css.areaNode
  44. });
  45. },
  46. createStartNode: function(){
  47. this.createNode = new Element("div", {
  48. "styles": this.css.createNode
  49. }).inject(this.areaNode);
  50. this.createNewNode = new Element("div", {
  51. "styles": this.css.createNewNode
  52. }).inject(this.createNode);
  53. this.formNode = new Element("div", {
  54. "styles": this.css.formNode
  55. }).inject(this.createNode);
  56. var html = "<table width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  57. "<tr><td colSpan=\"2\" style=\"height: 60px; line-height: 60px; text-align: center; font-size: 24px; font-weight: bold\">" +
  58. this.lp.start+" - "+this.categoryData.name+"</td></tr>" +
  59. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.department+":</td>" +
  60. "<td style=\"; text-align: left;\" id=\"form_startDepartment\"></td></tr>" +
  61. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.identity+":</td>" +
  62. "<td style=\"; text-align: left;\"><div id=\"form_startIdentity\"></div></td></tr>" +
  63. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.date+":</td>" +
  64. "<td style=\"; text-align: left;\"><div id=\"form_startDate\"></div></td></tr>" +
  65. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.subject+":</td>" +
  66. "<td style=\"; text-align: left;\"><input type=\"text\" id=\"form_startSubject\" " +
  67. "style=\"width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  68. "height: 26px;\"/></td></tr>" +
  69. "</table>";
  70. this.formNode.set("html", html);
  71. this.setStartFormContent();
  72. this.cancelActionNode = new Element("div", {
  73. "styles": this.css.cancelActionNode,
  74. "text": this.lp.cancel
  75. }).inject(this.formNode);
  76. this.startOkActionNode = new Element("div", {
  77. "styles": this.css.startOkActionNode,
  78. "text": this.lp.ok
  79. }).inject(this.formNode);
  80. this.cancelActionNode.addEvent("click", function(e){
  81. this.cancelStart(e);
  82. }.bind(this));
  83. this.startOkActionNode.addEvent("click", function(e){
  84. this.okStart(e);
  85. }.bind(this));
  86. },
  87. setStartFormContent: function(){
  88. this.dateArea = this.formNode.getElementById("form_startDate");
  89. var d = new Date();
  90. this.dateArea.set("text", d.format("%Y-%m-%d %H:%M"));
  91. this.departmentSelArea = this.formNode.getElementById("form_startDepartment");
  92. this.identityArea = this.formNode.getElementById("form_startIdentity");
  93. this.getOrgAction(function(){
  94. //if (!this.app.desktop.user.id){
  95. // this.orgAction.listPersonByKey(function(json){
  96. // if (json.data.length) this.app.desktop.user.id = json.data[0].id
  97. // this.loadDepartments();
  98. // }.bind(this), null, this.app.desktop.user.name);
  99. //}else{
  100. // this.loadDepartments();
  101. //}
  102. this.loadDepartments();
  103. }.bind(this));
  104. },
  105. loadDepartments: function(){
  106. if (this.app.desktop.session.user.name){
  107. this.orgAction.listIdentityByPerson(function(json){
  108. var selected = (json.data.length==1) ? true : false;
  109. json.data.each(function(id){
  110. var departSel = new MWF.xApplication.cms.Explorer.Starter.DepartmentSel(id, this, this.departmentSelArea, this.identityArea);
  111. if (selected) departSel.selected();
  112. }.bind(this));
  113. }.bind(this), null, this.app.desktop.session.user.name)
  114. }
  115. },
  116. getOrgAction: function(callback){
  117. if (!this.orgAction){
  118. MWF.require("MWF.xAction.org.express.RestActions", function(){
  119. this.orgAction = new MWF.xAction.org.express.RestActions();
  120. if (callback) callback();
  121. }.bind(this));
  122. }else{
  123. if (callback) callback();
  124. }
  125. },
  126. setStartNodeSize: function(){
  127. var size = this.app.content.getSize();
  128. var allSize = this.app.content.getSize();
  129. this.markNode.setStyles({
  130. "width": ""+allSize.x+"px",
  131. "height": ""+allSize.y+"px"
  132. });
  133. this.areaNode.setStyles({
  134. "width": ""+size.x+"px",
  135. "height": ""+size.y+"px"
  136. });
  137. var hY = size.y*0.8;
  138. var mY = size.y*0.2/2;
  139. this.createNode.setStyles({
  140. "height": ""+hY+"px",
  141. "margin-top": ""+mY+"px"
  142. });
  143. var iconSize = this.createNewNode.getSize();
  144. var formHeight = hY*0.7;
  145. if (formHeight>250) formHeight = 250;
  146. var formMargin = hY*0.3/2-iconSize.y;
  147. this.formNode.setStyles({
  148. "height": ""+formHeight+"px",
  149. "margin-top": ""+formMargin+"px"
  150. });
  151. },
  152. cancelStart: function(e){
  153. var _self = this;
  154. if ($("form_startSubject").get("value")){
  155. this.app.confirm("warn", e, this.lp.start_cancel_title, this.lp.start_cancel, "320px", "100px", function(){
  156. _self.markNode.destroy();
  157. _self.areaNode.destroy();
  158. this.close();
  159. },function(){
  160. this.close();
  161. }, null, this.app.content);
  162. }else{
  163. this.markNode.destroy();
  164. this.areaNode.destroy();
  165. }
  166. },
  167. okStart: function(e){
  168. var title = $("form_startSubject").get("value");
  169. this.getDocumentAction();
  170. var data = {
  171. "id" : this.documentAction.getUUID(),
  172. "isNewDocument" : true,
  173. "title": title,
  174. "creatorIdentity": this.identityArea.get("value"),
  175. "appId" :this.categoryData.appId,
  176. "catagoryId" : this.categoryData.id,
  177. "form" : this.categoryData.formId,
  178. "formName" :this.categoryData.formName,
  179. "docStatus" : "draft",
  180. "catagoryName" : this.categoryData.name,
  181. "categoryAlias" : this.categoryData.alias,
  182. "attachmentList" : []
  183. };
  184. if (!data.title){
  185. $("form_startSubject").setStyle("border-color", "red");
  186. $("form_startSubject").focus();
  187. this.app.notice(this.lp.inputSubject, "error");
  188. }else if (!data.creatorIdentity){
  189. this.departmentSelArea.setStyle("border-color", "red");
  190. this.app.notice(this.lp.selectStartId, "error");
  191. }else{
  192. this.mask = new MWF.widget.Mask({"style": "desktop"});
  193. this.mask.loadNode(this.areaNode);
  194. this.getDocumentAction(function(){
  195. this.documentAction.addDocument( data, function(json){
  196. this.mask.hide();
  197. this.markNode.destroy();
  198. this.areaNode.destroy();
  199. this.fireEvent("started", [json.data, title, this.categoryData.name]);
  200. //this.app.refreshAll();
  201. this.app.notice(this.lp.Started, "success");
  202. // this.app.processConfig();
  203. }.bind(this), null);
  204. }.bind(this));
  205. }
  206. },
  207. getDocumentAction: function(callback){
  208. if (!this.documentAction){
  209. MWF.xDesktop.requireApp("cms.Explorer", "Actions.RestActions", function(){
  210. this.documentAction = new MWF.xApplication.cms.Explorer.Actions.RestActions();
  211. if (callback) callback();
  212. }.bind(this));
  213. }else{
  214. if (callback) callback();
  215. }
  216. }
  217. });
  218. MWF.xApplication.cms.Explorer.Starter.DepartmentSel = new Class({
  219. initialize: function(data, starter, container, idArea){
  220. this.data = data;
  221. this.starter = starter;
  222. this.container = container;
  223. this.idArea = idArea;
  224. this.css = this.starter.css;
  225. this.isSelected = false;
  226. this.load();
  227. },
  228. load: function(){
  229. this.node = new Element("div", {"styles": this.css.departSelNode}).inject(this.container);
  230. this.starter.orgAction.getDepartmentByIdentity(function(department){
  231. this.node.set("text", department.data.name);
  232. }.bind(this), null, this.data.name);
  233. this.node.addEvents({
  234. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_over);}.bind(this),
  235. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_out);}.bind(this),
  236. "click": function(){
  237. this.selected();
  238. }.bind(this),
  239. });
  240. },
  241. selected: function(){
  242. if (!this.isSelected){
  243. if (this.starter.currentDepartment) this.starter.currentDepartment.unSelected();
  244. this.node.setStyles(this.css.departSelNode_selected);
  245. this.isSelected = true;
  246. this.starter.currentDepartment = this;
  247. this.idArea.set({
  248. "text": this.data.display,
  249. "value": this.data.name
  250. });
  251. }
  252. },
  253. unSelected: function(){
  254. if (this.isSelected){
  255. if (this.starter.currentDepartment) this.starter.currentDepartment = null;;
  256. this.node.setStyles(this.css.departSelNode);
  257. this.isSelected = false;
  258. }
  259. }
  260. });