CreateMainTask.js 19 KB

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