IndentityList.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. MWF.xApplication.ExeManager = MWF.xApplication.ExeManager || {};
  2. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  3. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  4. MWF.xDesktop.requireApp("ExeManager","Attachment",null,false);
  5. MWF.require("MWF.widget.Identity", null,false);
  6. MWF.xApplication.ExeManager.IndentityList = new Class({
  7. Extends: MWF.widget.Common,
  8. Implements: [Options, Events],
  9. options: {
  10. "style": "default"
  11. },
  12. initialize: function (node, app, actions, options) {
  13. this.setOptions(options);
  14. this.app = app;
  15. this.lp = app.lp;
  16. this.path = "/x_component_ExeManager/$IndentityList/";
  17. this.loadCss();
  18. this.actions = actions;
  19. this.node = $(node);
  20. },
  21. loadCss: function () {
  22. this.cssPath = "/x_component_ExeManager/$IndentityList/" + this.options.style + "/css.wcss";
  23. this._loadCss();
  24. },
  25. load: function () {
  26. this.middleContent = this.app.middleContent;
  27. this.middleContent.setStyles({"margin-top":"0px","border":"0px solid #f00","background-color":"#ffffff"});
  28. this.createToolBarContent();
  29. this.createContentDiv();
  30. this.resizeWindow();
  31. this.app.addEvent("resize", function(){
  32. this.resizeWindow();
  33. }.bind(this));
  34. },
  35. reload: function(){
  36. this.createToolBarContent();
  37. this.createContentDiv();
  38. },
  39. resizeWindow: function(){
  40. var size = this.app.middleContent.getSize();
  41. this.contentDiv.setStyles({"height":(size.y-110)+"px"});
  42. },
  43. createToolBarContent: function(){
  44. if(this.toolBarDiv) this.toolBarDiv.destroy();
  45. this.toolBarDiv = new Element("div.toolBarDiv",{"styles":this.css.toolBarDiv}).inject(this.middleContent);
  46. this.toolBarActionDiv = new Element("div.toolBarActionDiv",{"styles":this.css.toolBarActionDiv}).inject(this.toolBarDiv);
  47. this.toolBarSearchDiv = new Element("div.toolBarSearchDiv",{"styles":this.css.toolBarSearchDiv}).inject(this.toolBarDiv);
  48. this.toolBarSearchInput = new Element("input.toolBarSearchInput",{
  49. "styles":this.css.toolBarSearchInput
  50. }).inject(this.toolBarSearchDiv);
  51. this.toolBarSearchInput.addEvents({
  52. "keyup":function(e){
  53. if(e.code == 13){
  54. this.searchView(this.toolBarSearchInput.get("value"))
  55. }
  56. }.bind(this)
  57. });
  58. this.toolBarSearchActionBtn = new Element("div.toolBarSearchBtn",{
  59. "styles":this.css.toolBarSearchBtn,
  60. "text": this.lp.IndentityList.searchAction
  61. }).inject(this.toolBarSearchDiv);
  62. this.toolBarSearchActionBtn.addEvents({
  63. "click":function(){
  64. this.searchView(this.toolBarSearchInput.get("value"))
  65. }.bind(this)
  66. });
  67. //this.toolBarSearchResetBtn = new Element("div.toolBarSearchBtn",{
  68. // "styles":this.css.toolBarSearchBtn,
  69. // "text":"重置"
  70. //}).inject(this.toolBarSearchDiv);
  71. this.toolBarStatusDiv = new Element("div.toolBarStatusDiv",{
  72. "styles":this.css.toolBarStatusDiv
  73. }).inject(this.toolBarDiv);
  74. this.toolBarStatusDiv.setStyle("display","none");
  75. this.toolBarStatusAllDiv = new Element("div.toolBarStatusAllDiv",{styles:this.css.toolBarStatusAllDiv}).inject(this.toolBarStatusDiv);
  76. this.toolBarStatusPercentDiv = new Element("div.toolBarStatusPercentDiv",{styles:this.css.toolBarStatusPercentDiv}).inject(this.toolBarStatusDiv);
  77. },
  78. createContentDiv: function(key){
  79. if(this.contentDiv) this.contentDiv.destroy();
  80. this.contentDiv = new Element("div.contentDiv",{"styles":this.css.contentDiv}).inject(this.middleContent);
  81. if(this.scrollBar && this.scrollBar.scrollVAreaNode){
  82. this.scrollBar.scrollVAreaNode.destroy();
  83. }
  84. MWF.require("MWF.widget.ScrollBar", function () {
  85. this.scrollBar = new MWF.widget.ScrollBar(this.contentDiv, {
  86. "indent": false,
  87. "style": "xApp_TaskList",
  88. "where": "before",
  89. "distance": 30,
  90. "friction": 4,
  91. "axis": {"x": false, "y": true},
  92. "onScroll": function (y) {
  93. var scrollSize = this.contentDiv.getScrollSize();
  94. var clientSize = this.contentDiv.getSize();
  95. var scrollHeight = scrollSize.y - clientSize.y;
  96. var view = this.view;
  97. if (y + 200 > scrollHeight && view && view.loadElementList) {
  98. if (! view.isItemsLoaded) view.loadElementList();
  99. }
  100. }.bind(this)
  101. });
  102. }.bind(this),false);
  103. var templateUrl = this.path+"listItem.json";
  104. var filter = {
  105. identity:key
  106. };
  107. if(this.view) delete this.view;
  108. this.view = new MWF.xApplication.ExeManager.IndentityList.View(this.contentDiv, this.app, {explorer:this,lp : this.lp.IndentityList, css : this.css, actions : this.actions }, { templateUrl : templateUrl,category:"",filterData:filter } );
  109. this.view.load();
  110. },
  111. searchView: function(key){
  112. this.createContentDiv(key);
  113. this.resizeWindow();
  114. },
  115. showErrorMsg: function(xhr,text,error){
  116. var errorText = error;
  117. var errorMessage;
  118. if (xhr) errorMessage = xhr.responseText;
  119. try{
  120. var e = JSON.parse(errorMessage);
  121. if (e && e.message) {
  122. this.app.notice(e.message, "error");
  123. } else {
  124. this.app.notice(errorText, "error");
  125. }
  126. }catch(e){
  127. this.app.notice("failure", "error");
  128. }
  129. }
  130. });
  131. MWF.xApplication.ExeManager.IndentityList.View = new Class({
  132. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  133. _createDocument: function(data){
  134. return new MWF.xApplication.ExeManager.IndentityList.Document(this.viewNode, data, this.explorer, this);
  135. },
  136. _getCurrentPageData: function(callback, count){
  137. if (!count)count = 20;
  138. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  139. var filter = this.options.filterData || {};
  140. if(id=="(0)")this.app.createShade();
  141. this.actions.getErrorIndentitytNext(id, count, filter, function (json) {
  142. if (callback)callback(json);
  143. this.app.destroyShade();
  144. }.bind(this),function(xhr,error,text){
  145. this.explorer.explorer.showErrorMsg(xhr,error,text)
  146. }.bind(this))
  147. },
  148. _create: function(){
  149. },
  150. _openDocument: function( documentData ){
  151. this.indentityForm = new MWF.xApplication.ExeManager.IndentityList.IndentityForm(this.explorer.explorer, this.actions, documentData, {
  152. "isNew": false,
  153. "isEdited": false,
  154. "onReloadView" : function( data ){
  155. this.app.topBarContent.getElements(".topBarLi").each(function(d){
  156. if(d.get("id") == "topIndentity"){
  157. d.click()
  158. }
  159. }.bind(this));
  160. }.bind(this)
  161. });
  162. this.indentityForm.load();
  163. },
  164. _queryCreateViewNode: function(){
  165. },
  166. _postCreateViewNode: function( viewNode ){
  167. },
  168. _queryCreateViewHead:function(){
  169. },
  170. _postCreateViewHead: function( headNode ){
  171. }
  172. });
  173. MWF.xApplication.ExeManager.IndentityList.Document = new Class({
  174. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  175. action_open: function(e){
  176. }
  177. });
  178. MWF.xApplication.ExeManager.IndentityList.IndentityForm = new Class({
  179. Extends: MWF.xApplication.Template.Explorer.PopupForm,
  180. Implements: [Options, Events],
  181. options: {
  182. "style": "default",
  183. "width": "90%",
  184. "height": "100%",
  185. "top" : 0,
  186. "left" : 0,
  187. "hasTop": true,
  188. "hasIcon": false,
  189. "hasBottom": true,
  190. "title": "",
  191. "draggable": false,
  192. "closeAction": true,
  193. "isNew": false,
  194. "isEdited": false
  195. },
  196. initialize: function (explorer, actions, data, options) {
  197. this.setOptions(options);
  198. this.explorer = explorer;
  199. this.app = explorer.app;
  200. this.lp = this.app.lp.indentityForm;
  201. this.actions = this.app.restActions;
  202. this.path = "/x_component_ExeManager/$IndentityList/";
  203. this.cssPath = this.path + this.options.style + "/indentityForm.wcss";
  204. this._loadCss();
  205. this.options.title = this.lp.title;
  206. this.data = data || {};
  207. this.actions = actions;
  208. },
  209. load: function () {
  210. if(this.data.id){
  211. //var data = {identity:"史敬(市场部)"}
  212. var data = {identity:this.data.identity};
  213. this.actions.getErrorIdentityDetail(data,function(json){
  214. if(json.data) this.detailsData = json.data;
  215. }.bind(this),null,false)
  216. }
  217. if (this.options.isNew) {
  218. this.create();
  219. } else if (this.options.isEdited) {
  220. this.edit();
  221. } else {
  222. this.open();
  223. }
  224. },
  225. _open: function () {
  226. this.formMarkNode = new Element("div.formMarkNode", {
  227. "styles": this.css.formMarkNode,
  228. "events": {
  229. "mouseover": function (e) {
  230. e.stopPropagation();
  231. },
  232. "mouseout": function (e) {
  233. e.stopPropagation();
  234. },
  235. "click": function (e) {
  236. e.stopPropagation();
  237. }
  238. }
  239. }).inject(this.app.content);
  240. this.formAreaNode = new Element("div.formAreaNode", {
  241. "styles": this.css.formAreaNode
  242. });
  243. this.createFormNode();
  244. this.formAreaNode.inject(this.formMarkNode, "after");
  245. this.formAreaNode.fade("in");
  246. this.setFormNodeSize();
  247. this.setFormNodeSizeFun = this.setFormNodeSize.bind(this);
  248. this.app.addEvent("resize", this.setFormNodeSizeFun);
  249. if (this.options.draggable && this.formTopNode) {
  250. var size = this.app.content.getSize();
  251. var nodeSize = this.formAreaNode.getSize();
  252. this.formAreaNode.makeDraggable({
  253. "handle": this.formTopNode,
  254. "limit": {
  255. "x": [0, size.x - nodeSize.x],
  256. "y": [0, size.y - nodeSize.y]
  257. }
  258. });
  259. }
  260. },
  261. createTopNode: function () {
  262. if (!this.formTopNode) {
  263. this.formTopNode = new Element("div.formTopNode", {
  264. "styles": this.css.formTopNode
  265. }).inject(this.formNode);
  266. this.formTopIconNode = new Element("div", {
  267. "styles": this.css.formTopIconNode
  268. }).inject(this.formTopNode);
  269. this.formTopTextNode = new Element("div", {
  270. "styles": this.css.formTopTextNode,
  271. "text": this.options.title
  272. }).inject(this.formTopNode);
  273. if (this.options.closeAction) {
  274. this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  275. this.formTopCloseActionNode.addEvent("click", function () {
  276. this.close()
  277. }.bind(this))
  278. }
  279. this.formTopContentNode = new Element("div", {
  280. "styles": this.css.formTopContentNode
  281. }).inject(this.formTopNode);
  282. this._createTopContent();
  283. }
  284. },
  285. _createTopContent: function () {
  286. },
  287. _createTableContent: function () {
  288. if(this.formTableArea) this.formTableArea.empty();
  289. this.modifyDiv = new Element("div.modifyDiv",{"styles":this.css.modifyDiv}).inject(this.formTableArea);
  290. this.oldIdentitySpan = new Element("span.oldIdentitySpan",{"styles":this.css.oldIdentitySpan,"text":this.lp.oldIdentity+": "+this.data.identity}).inject(this.modifyDiv);
  291. this.newIdentitySpan = new Element("span.newIdentitySpan",{"styles":this.css.newIdentitySpan,"text":this.lp.newIdentity+": "}).inject(this.modifyDiv);
  292. this.newIdentityInput = new Element("input.newIdentityInput",{
  293. "styles":this.css.newIdentityInput,
  294. "readonly":true,
  295. "type":"text"
  296. }).inject(this.modifyDiv);
  297. this.newIdentityInput.addEvents({
  298. "click":function(){
  299. this.selectPerson(this.newIdentityInput,"identity");
  300. }.bind(this)
  301. });
  302. this.modifyBottonDiv = new Element("div.modifyBottonDiv",{
  303. "styles":this.css.modifyBottonDiv,
  304. "text":this.lp.modify
  305. }).inject(this.modifyDiv);
  306. this.modifyBottonDiv.addEvents({
  307. "click":function(e){
  308. if(this.newIdentityInput.get("value") == ""){
  309. this.app.notice(this.lp.newIdentityEmpty,"error");
  310. }else{
  311. this.replaceIdentity(e);
  312. }
  313. }.bind(this)
  314. })
  315. this.contentDiv = new Element("div.contentDiv",{"styles":this.css.contentDiv}).inject(this.formTableArea);
  316. this.naviTabDiv = new Element("div.naviTabDiv",{"styles":this.css.naviTabDiv}).inject(this.contentDiv);
  317. if(this.detailsData){
  318. var _self = this;
  319. this.detailsData.each(function(d){
  320. var categoryLi = new Element("li.categoryLi",{
  321. "styles" : this.css.categoryLi,
  322. "text": d.recordType
  323. }).inject(this.naviTabDiv);
  324. categoryLi.addEvents({
  325. "click":function(){
  326. _self.loadList(this);
  327. }
  328. });
  329. }.bind(_self));
  330. _self.naviTabDiv.getElements("li")[0].click();
  331. }
  332. },
  333. _createBottomContent: function () {
  334. this.cancelActionNode = new Element("div.formCancelActionNode", {
  335. "styles": this.css.formCancelActionNode,
  336. "text": this.lp.close
  337. }).inject(this.formBottomNode);
  338. this.cancelActionNode.addEvent("click", function (e) {
  339. this.cancel(e);
  340. }.bind(this));
  341. },
  342. loadList:function(o){
  343. this.naviTabDiv.getElements("li").setStyles({"border-bottom":""});
  344. o.setStyles({"border-bottom":"2px solid #124c93"});
  345. if(this.contentList) this.contentList.destroy();
  346. this.contentList = new Element("div.contentList",{"styles":this.css.contentList}).inject(this.formTableArea);
  347. if(this.table) this.table.destroy();
  348. this.table = new Element("table.table",{"styles":{"width":"100%"}}).inject(this.contentList);
  349. var tr = new Element("tr.tr").inject(this.table);
  350. var td = new Element("td.td",{"text":this.lp.tableTitle,"align":"left","styles":{"padding-left":"200px","font-weight":"bold"}}).inject(tr);
  351. this.detailsData.each(function(d){
  352. if(d.recordType == o.get("text")){
  353. this.listData = d.errorRecords;
  354. }
  355. }.bind(this));
  356. this.listData.each(function(d,i){
  357. tr = new Element("tr.tr").inject(this.table);
  358. var color = i%2 == 0?"#f1f1f1":"#fff";
  359. tr.setStyles({"background-color":color});
  360. td = new Element("td.td",{
  361. "styles":this.css.tableTd,
  362. "text": d.title
  363. }).inject(tr)
  364. }.bind(this))
  365. },
  366. replaceIdentity:function(e){
  367. var _self = this;
  368. this.app.confirm("warn",e,this.lp.warn.warnTitle,this.lp.warn.warnContent,300,120,function(){
  369. var submitData = {
  370. oldIdentity:_self.data.identity,
  371. newIdentity :_self.newIdentityInput.get("value"),
  372. recordType:"all",
  373. recordId:"all",
  374. tableName:"all"
  375. };
  376. _self.app.createShade();
  377. _self.actions.replaceErrorIdentity(submitData, function(json){
  378. _self.app.notice(_self.lp.modifySuccess,"success");
  379. _self.app.destroyShade();
  380. _self.close();
  381. _self.fireEvent("reloadView");
  382. }.bind(_self),function(xhr,text,error){
  383. _self.app.showErrorMessage(xhr,text,error);
  384. _self.app.destroyShade();
  385. }.bind(_self));
  386. this.close();
  387. },function(){
  388. this.close();
  389. })
  390. },
  391. selectPerson: function( item, type ){
  392. MWF.xDesktop.requireApp("Organization", "Selector.package",null, false);
  393. this.fireEvent("querySelect", this);
  394. var value = item.get("value").split( this.valSeparator );
  395. var options = {
  396. "type": type,
  397. "title": "select",
  398. "count" : 1,
  399. "names": value || [],
  400. //"departments" : this.options.departments,
  401. //"companys" : this.options.companys,
  402. "onComplete": function(items){
  403. var arr = [];
  404. items.each(function(item){
  405. arr.push(item.data.name);
  406. }.bind(this));
  407. item.set("value",arr.join(","));
  408. //this.items[0].fireEvent("change");
  409. }.bind(this)
  410. };
  411. var selector = new MWF.OrgSelector(this.app.content, options);
  412. }
  413. });