CreateMainTask.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. MWF.xApplication.Execution = MWF.xApplication.Execution || {};
  2. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  3. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  4. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  5. MWF.xApplication.Execution.CreateMainTask = new Class({
  6. Extends: MPopupForm,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default",
  10. "width": "95%",
  11. "height": "95%",
  12. "hasTop": true,
  13. "hasIcon": false,
  14. "hasBottom": true,
  15. "title": "",
  16. "draggable": true,
  17. "closeAction": true,
  18. "isNew": false,
  19. "isEdited": false
  20. },
  21. initialize: function (explorer, actions, data, options) {
  22. this.setOptions(options);
  23. this.explorer = explorer;
  24. this.app = explorer.app;
  25. this.lp = this.app.lp;
  26. this.path = "/x_component_Execution/$CreateMainTask/";
  27. this.cssPath = this.path + this.options.style + "/css.wcss";
  28. this._loadCss();
  29. this.options.title = "";
  30. this.data = data || {};
  31. this.actions = actions;
  32. },
  33. load: function () {
  34. if (this.options.isNew) {
  35. this.create();
  36. } else if (this.options.isEdited) {
  37. this.edit();
  38. } else {
  39. this.open();
  40. }
  41. var vh = this.formContentNode.getSize().y-this.mainTaskDiv.getSize().y
  42. vh = vh-30
  43. //this.subTaskDiv.setStyles({"height":vh+"px"});
  44. },
  45. _open : function(){
  46. this.formMaskNode = new Element("div.formMaskNode", {
  47. "styles": this.css.formMaskNode,
  48. "events": {
  49. "mouseover": function(e){e.stopPropagation();},
  50. "mouseout": function(e){e.stopPropagation();}
  51. }
  52. }).inject(this.app.content );
  53. this.formAreaNode = new Element("div.formAreaNode", {
  54. "styles": this.css.formAreaNode
  55. });
  56. this.createFormNode();
  57. this.formAreaNode.inject(this.formMaskNode, "after");
  58. this.formAreaNode.fade("in");
  59. this.setFormNodeSize();
  60. this.setFormNodeSizeFun = this.setFormNodeSize.bind(this);
  61. this.addEvent("resize", this.setFormNodeSizeFun);
  62. if( this.options.draggable && this.formTopNode ){
  63. var size = this.app.content.getSize();
  64. var nodeSize = this.formAreaNode.getSize();
  65. this.formAreaNode.makeDraggable({
  66. "handle": this.formTopNode,
  67. "limit": {
  68. "x": [0, size.x-nodeSize.x],
  69. "y": [0, size.y-nodeSize.y]
  70. }
  71. });
  72. }
  73. },
  74. createTopNode: function () {
  75. var htmlStr="";
  76. if (!this.formTopNode) {
  77. this.formTopNode = new Element("div.formTopNode", {
  78. "styles": this.css.formTopNode
  79. }).inject(this.formNode);
  80. //this.formTopTextNode = new Element("div", {
  81. // "styles": this.css.formTopTextNode,
  82. // "text": this.options.title
  83. //}).inject(this.formTopNode)
  84. if (this.options.closeAction) {
  85. this.formTopCloseActionNode = new Element("div.formTopCloseActionNode", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  86. this.formTopCloseActionNode.addEvent("click", function () {
  87. this.close()
  88. }.bind(this))
  89. }
  90. this.formTopContentNode = new Element("div", {
  91. "styles": this.css.formTopContentNode
  92. }).inject(this.formTopNode)
  93. this._createTopContent();
  94. }
  95. },
  96. _createTopContent: function () {
  97. this.topTitleLi = new Element("li.topTitleLi", {
  98. "styles": this.css.topTitleLi
  99. }).inject(this.formTopContentNode);
  100. htmlStr = "<img class='topTitleImg' style='width:25px; height:25px;margin-top:10px;' src='/x_component_Execution/$Main/default/icon/Document-104.png' />";
  101. htmlStr += "<span class='topTitleSpan' style='position:absolute;margin-top:0px;'>"+MWF.xApplication.Execution.LP.createMainTask.topTitle+"</span>";
  102. this.topTitleLi.set("html",htmlStr);
  103. this.user = layout.desktop.session.user.name;
  104. this.userGender = layout.desktop.session.user.genderType;
  105. this.department="";
  106. this.restActions = new MWF.xApplication.Execution.Actions.RestActions();
  107. this.restActions.listDepartmentByPerson( function( json ){
  108. this.department = json["data"][0]["display"];
  109. }.bind(this), null, layout.desktop.session.user.name, false);
  110. var nowTime = new Date();
  111. var nowFormat = nowTime.getFullYear()+"-"+(nowTime.getMonth()+1)+"-"+nowTime.getDay()+" "+nowTime.getHours()+":"+nowTime.getMinutes()+":"+nowTime.getSeconds();
  112. this.topInforLi = new Element("li.topInforLi",{
  113. "styles":this.css.topInforLi
  114. }).inject(this.formTopContentNode);
  115. this.topInforDrafterSpan = new Element("span.topInforDrafterSpan",{
  116. "styles":this.css.topInforSpan,
  117. "text":MWF.xApplication.Execution.LP.createMainTask.drafter+this.user
  118. }).inject(this.topInforLi);
  119. this.topInforDeptSpan = new Element("span.topInforDeptSpan",{
  120. "styles":this.css.topInforSpan,
  121. "text":MWF.xApplication.Execution.LP.createMainTask.drafterDept+this.department
  122. }).inject(this.topInforLi);
  123. this.topInforDateSpan = new Element("span.topInforDateSpan",{
  124. "styles":this.css.topInforSpan,
  125. "text":MWF.xApplication.Execution.LP.createMainTask.drafterDate+nowFormat
  126. }).inject(this.topInforLi);
  127. },
  128. _createTableContent: function () {
  129. this.mainTaskDiv = new Element("div.mainTaskDiv", {
  130. "styles": this.css.mainTaskDiv
  131. }).inject(this.formTableArea);
  132. this.createMainTask();
  133. this.createTaskList();
  134. //this.createBottomAction();
  135. },
  136. reloadMainTask: function( data ){
  137. this.mainTaskDiv.empty();
  138. this.createMainTask( data );
  139. },
  140. createMainTask: function( data ) {
  141. if(data){
  142. this.topInforDrafterSpan.set("text",MWF.xApplication.Execution.LP.createMainTask.drafter+data.creatorName)
  143. this.topInforDeptSpan.set("text",MWF.xApplication.Execution.LP.createMainTask.drafterDept+data.creatorOrganizationName)
  144. this.topInforDateSpan.set("text",MWF.xApplication.Execution.LP.createMainTask.drafterDate+data.createTime)
  145. }
  146. data = data || {
  147. processIdentity : this.app.identity,
  148. deployerName : this.app.user,
  149. creatorName : this.app.user
  150. }
  151. if(data.id){
  152. this.centerWorkId = data.id;
  153. }
  154. if(this.data.id){
  155. this.centerWorkId = this.data.id;
  156. this.getMainTask(this.centerWorkId, function( json ){
  157. data = json.data
  158. }.bind(this));
  159. }
  160. //alert(JSON.stringify(data))
  161. this.mainTaskTitleDiv = new Element("div.mainTaskTitleDiv", {
  162. "styles": this.css.mainTaskTitleDiv,
  163. "text": this.lp.createMainTask.mainTask.topTitle
  164. }).inject(this.mainTaskDiv);
  165. this.mainTaskContentDiv = new Element("div.mainTaskContentDiv").inject(this.mainTaskDiv);
  166. var html = "<table width='100%' border='0' styles=''>" +
  167. "<tr><td styles='mainTaskTitle' lable='mainTaskTitle'></td>" +
  168. " <td styles='mainTaskTitleValue' colspan='5' item='mainTaskTitle'></td></tr>" +
  169. "<tr>" +
  170. "<td styles='mainTaskCategory' lable='mainTaskCategory'></td>" +
  171. "<td styles='mainTaskCategoryValue' item='mainTaskCategory'></td>" +
  172. "<td styles='mainTaskLevel' lable='mainTaskLevel'></td>" +
  173. "<td styles='mainTaskLevelValue' item='mainTaskLevel'></td>" +
  174. "<td styles='mainTaskLimit' lable='mainTaskLimit'></td>" +
  175. "<td styles='mainTaskLimitValue' item='mainTaskLimit'></td>" +
  176. "</tr>" +
  177. "<tr><td styles='mainTaskDescription' lable='mainTaskDescription'></td>" +
  178. " <td styles='mainTaskDescriptionValue' item='mainTaskDescription' colspan='5'></td></tr>" +
  179. "</table>"
  180. this.mainTaskContentDiv.set("html", html);
  181. var form=this.form = new MForm(this.mainTaskContentDiv, data, {
  182. style : "execution",
  183. isEdited: this.options.isEdited,
  184. itemTemplate: {
  185. //deployerName:{
  186. // defaultValue:"ffff"
  187. //},
  188. mainTaskTitle: {
  189. text: this.lp.createMainTask.mainTask.title + ":", type: "text",
  190. style:{"color":"#999999"},
  191. name : "title",
  192. notEmpty:true
  193. },
  194. mainTaskCategory: {
  195. text: this.lp.createMainTask.mainTask.category+":",
  196. style : {"width":"90%","height":"30px","color":"#999999","border-radius":"1px","box-shadow": "0px 0px 1px #CCC"},
  197. type: "select",
  198. selectValue : this.lp.createMainTask.mainTask.categoryValue,
  199. name : "defaultWorkType",
  200. notEmpty:true
  201. },
  202. mainTaskLevel: {
  203. text: this.lp.createMainTask.mainTask.level + ":",
  204. type: "select",
  205. name : "defaultWorkLevel",
  206. selectValue : this.lp.createMainTask.mainTask.level,
  207. style : {"width":"90%","height":"30px","color":"#999999","border-radius":"1px","box-shadow": "0px 0px 1px #CCC"},
  208. notEmpty:true
  209. },
  210. mainTaskLimit: {
  211. text: this.lp.createMainTask.mainTask.limit + ":",
  212. type: "text",
  213. name : "defaultCompleteDateLimitStr",
  214. style:{"width":"90%","color":"#999999"},tType:"date",
  215. attr:{"readonly":true},
  216. notEmpty:true,
  217. event:{
  218. }
  219. },
  220. mainTaskDescription: {
  221. text: this.lp.createMainTask.mainTask.description + ":",
  222. type: "textarea",
  223. name:"description",
  224. notEmpty:true,
  225. style:{"height":"60px","color":"#999999"}
  226. }
  227. }
  228. }, this.app, this.css);
  229. form.load();
  230. },
  231. createTaskList : function(){
  232. this.subTaskDiv = new Element("div.subTaskDiv", {
  233. "styles": this.css.subTaskDiv
  234. }).inject(this.formTableArea);
  235. this.subTaskTitleDiv = new Element("div.subTaskTitleDiv",{
  236. "styles":this.css.subTaskTitleDiv,
  237. "text":this.lp.createMainTask.subTask.topTitle
  238. }).inject(this.subTaskDiv);
  239. this.subTaskContentDiv = new Element("div.subTaskContentDiv",{
  240. "styles":this.css.subTaskContentDiv
  241. }).inject(this.subTaskDiv);
  242. this.loadBaseWork();
  243. },
  244. createBottomNode : function(){
  245. this.formBottomNode = new Element("div.formBottomNode", {
  246. "styles": this.css.formBottomNode
  247. }).inject(this.formNode);
  248. this.createBottomAction()
  249. },
  250. createBottomAction:function(){
  251. this.bottomDiv = new Element("div.bottomDiv", {
  252. "styles": this.css.bottomDiv
  253. }).inject(this.formBottomNode);
  254. this.bottomActionLi = new Element("div.bottomActionLi",{
  255. "styles":this.css.bottomActionLi
  256. }).inject(this.bottomDiv);
  257. this.bottomNewWorkSpan = new Element("span.bottomNewWorkSpan",{
  258. "styles":this.css.bottomNewWorkSpan,
  259. "text": this.lp.createMainTask.action.newWork
  260. }).inject(this.bottomActionLi)
  261. .addEvents({
  262. "click":function(){
  263. var r = this.form.getResult(true,",",true,false,true)
  264. if( !r ){
  265. return
  266. }
  267. this.saveMainTask( r, function( json ){
  268. if( json.data.status === "ERROR"){
  269. this.app.notice(json.data.message, "error")
  270. }else{
  271. this.getMainTask(json.data.message, function( data ){
  272. this.reloadMainTask( data.data )
  273. this.openWorkForm( data.data );
  274. }.bind(this))
  275. }
  276. }.bind(this) )
  277. }.bind(this)
  278. });
  279. //this.bottomDraftWorkSpan = new Element("span.bottomDraftWorkSpan",{
  280. // "styles":this.css.bottomDraftWorkSpan,
  281. // "text": this.lp.createMainTask.action.draftWork
  282. //}).inject(this.bottomActionLi);
  283. this.bottomDoWork = new Element("span.bottomDoWork",{
  284. "styles":this.css.bottomDoWork,
  285. "text": this.lp.createMainTask.action.doWork
  286. }).inject(this.bottomActionLi)
  287. .addEvents({
  288. "click":function(){
  289. var ids = [];
  290. this.actions.getUserBaseWork(this.centerWorkId, function (json) {
  291. Array.each(json.data,function(item,index){
  292. ids.push(item.id)
  293. })
  294. }.bind(this),null,false)
  295. var sendData = {};
  296. sendData.deployerIdentity = "";
  297. sendData.workIds = ids
  298. this.actions.deployBaseWork(sendData, function (json) {
  299. }.bind(this),null,false);
  300. if(this.app.workTask.contentDiv) this.app.workTask.contentDiv.destroy()
  301. this.app.workTask.createContentDiv();
  302. this.close();
  303. }.bind(this)
  304. })
  305. this.bottomIconLi = new Element("div.bottomIconLi",{
  306. "styles":this.css.bottomIconLi
  307. }).inject(this.bottomDiv);
  308. this.bottomIconImg = new Element("img.bottomIconImg",{
  309. "styles":this.css.bottomIconImg,
  310. "src":"/x_component_Execution/$Main/default/icon/okr.png"
  311. }).inject(this.bottomIconLi);
  312. },
  313. saveMainTask: function(data, callback){
  314. this.app.restActions.saveMainTask( data, function(json){
  315. if( callback )callback(json);
  316. }.bind(this));
  317. },
  318. getMainTask: function(id, callback){
  319. this.app.restActions.getMainTask( id, function(json){
  320. if( callback )callback(json);
  321. }.bind(this),null,false);
  322. },
  323. openWorkForm : function( data ){
  324. this.view._create( data );
  325. },
  326. loadBaseWork:function(){
  327. //alert("id="+this.centerWorkId);
  328. this.subTaskContentDiv.empty();
  329. //if(this.centerWorkId && this.centerWorkId!=""){
  330. this.view = new MWF.xApplication.Execution.CreateMainTask.BaseWorkView(this.subTaskContentDiv, this.app, this,
  331. this.css, this.lp.baseWorkView, this.actions, {
  332. templateUrl : this.path+"listItem.json", centerWorkId: this.centerWorkId
  333. } )
  334. this.view.load();
  335. //}
  336. }
  337. })
  338. MWF.xApplication.Execution.CreateMainTask.BaseWorkView = new Class({
  339. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  340. initialize: function (container, app, explorer, css, lp, actions, options) {
  341. this.container = container;
  342. this.app = app;
  343. this.explorer = explorer;
  344. this.css = css;
  345. this.lp = lp
  346. this.actions = actions;
  347. if (!options.templateUrl) {
  348. options.templateUrl = this.explorer.path + "listItem.json"
  349. } else if (options.templateUrl.indexOf("/") == -1) {
  350. options.templateUrl = this.explorer.path + options.templateUrl;
  351. }
  352. this.setOptions(options);
  353. },
  354. _createDocument: function(data){
  355. return new MWF.xApplication.Execution.CreateMainTask.BaseWorkDocument(this.viewNode, data, this.explorer, this);
  356. },
  357. _getCurrentPageData: function(callback, count){
  358. this.centerWorkId = this.options.centerWorkId;
  359. this.actions.getUserBaseWork(this.centerWorkId, function (json) {
  360. //alert(JSON.stringify(json));
  361. if (callback)callback(json);
  362. }.bind(this),null,false)
  363. },
  364. _removeDocument: function(documentData, all){
  365. this.actions.deleteBaseWork(documentData.id, function(json){
  366. this.reload();
  367. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  368. }.bind(this));
  369. },
  370. _create: function( data ){
  371. MWF.xDesktop.requireApp("Execution", "WorkForm", function(){
  372. this.workform = new MWF.xApplication.Execution.WorkForm(this, this.app.restActions,{"centerWorkId": data.id || this.options.centerWorkId },{
  373. "isNew": true,
  374. "isEdited": false
  375. });
  376. //alert("cccc="+this.centerWorkId)
  377. this.workform.load();
  378. }.bind(this));
  379. },
  380. _openDocument: function( documentData ){
  381. //this.workForm = new MWF.xApplication.Execution.WorkForm(this, this.actions, documentData, {
  382. // "isNew": false,
  383. // "isEdited": false
  384. //})
  385. //this.workForm.load();
  386. //MWF.xDesktop.requireApp("Execution", "CreateMainTask", function(){
  387. // this.centerWork = new MWF.xApplication.Execution.CreateMainTask(this, this.actions,{"id":documentData.id,"name":"fff"},{} );
  388. // this.centerWork.load();
  389. //}.bind(this))
  390. },
  391. _queryCreateViewNode: function(){
  392. },
  393. _postCreateViewNode: function( viewNode ){
  394. },
  395. _queryCreateViewHead:function(){
  396. },
  397. _postCreateViewHead: function( headNode ){
  398. }
  399. })
  400. MWF.xApplication.Execution.CreateMainTask.BaseWorkDocument = new Class({
  401. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  402. action_delete : function(){
  403. this.view.app.restActions.deleteBaseWork( this.data.id, function(json){
  404. //alert(JSON.stringify(json))
  405. this.view.app.notice(this.app.lp.deleteDocumentOK, "success");
  406. this.view.reload();
  407. }.bind(this));
  408. },
  409. action_edit:function(){
  410. //alert("edit");
  411. //alert(JSON.stringify(this.data))
  412. MWF.xDesktop.requireApp("Execution", "WorkForm", function(){
  413. var workform = new MWF.xApplication.Execution.WorkForm(this.view, this.view.app.restActions,this.data,{
  414. "isNew": false,
  415. "isEdited": true
  416. });
  417. workform.load();
  418. }.bind(this));
  419. //MWF.xDesktop.requireApp("Execution", "CreateMainTask", function(){
  420. // //this.clearContent();
  421. // //this.explorerContent = new Element("div", {
  422. // // "styles": this.css.rightContentNode
  423. // //}).inject(this.node);
  424. // this.centerWork = new MWF.xApplication.Execution.CreateMainTask(this.view, this.view.app.RestActions,{"id":this.data.id,"name":"fff"},{} );
  425. // this.centerWork.load();
  426. //}.bind(this))
  427. },
  428. _queryCreateDocumentNode:function( itemData ){
  429. },
  430. _postCreateDocumentNode: function( itemNode, itemData ){
  431. }
  432. //open: function(){
  433. // alert("open")
  434. //}
  435. })