Customer.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. MWF.xApplication.CRM = MWF.xApplication.CRM || {};
  2. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  3. MWF.xDesktop.requireApp("CRM", "Template", null,false);
  4. MWF.xDesktop.requireApp("Template", "Explorer", null,false);
  5. MWF.require("MWF.widget.Identity", null,false);
  6. MWF.xDesktop.requireApp("Forum", "Actions.RestActions", null, false);
  7. MWF.xApplication.CRM.Customer = new Class({
  8. Extends: MWF.widget.Common,
  9. Implements: [Options, Events],
  10. options: {
  11. "style": "default"
  12. },
  13. initialize: function (node, app, actions, options) {
  14. this.setOptions(options);
  15. this.app = app;
  16. this.lp = app.lp.customer;
  17. this.path = "/x_component_CRM/$Customer/";
  18. this.loadCss();
  19. this.actions = actions;
  20. this.node = $(node);
  21. },
  22. loadCss: function () {
  23. this.cssPath = "/x_component_CRM/$Customer/" + this.options.style + "/css.wcss";
  24. this._loadCss();
  25. },
  26. load: function () {
  27. this.testActions = new MWF.xApplication.Forum.Actions.RestActions();
  28. if(this.formContentArr)this.formContentArr.empty();
  29. this.formContentArr = [];
  30. if(this.formMarkArr)this.formMarkArr.empty();
  31. this.formMarkArr = [];
  32. this.rightContentDiv = this.app.rightContentDiv;
  33. this.createHeadContent();
  34. this.createToolBarContent();
  35. this.createCustomerContent();
  36. this.resizeWindow();
  37. this.app.addEvent("resize", function(){
  38. this.resizeWindow();
  39. }.bind(this));
  40. },
  41. reload:function(){
  42. this.createCustomerContent();
  43. this.resizeWindow();
  44. },
  45. createHeadContent:function(){
  46. if(this.headContentDiv) this.headContentDiv.destroy();
  47. this.headContentDiv = new Element("div.headContentDiv",{"styles":this.css.headContentDiv}).inject(this.rightContentDiv);
  48. this.headTitleDiv = new Element("div.headTitleDiv",{
  49. "styles":this.css.headTitleDiv,
  50. "text":this.lp.head.headTitle
  51. }).inject(this.headContentDiv);
  52. //search
  53. this.headSearchDiv = new Element("div.headSearchDiv",{"styles":this.css.headSearchDiv}).inject(this.headContentDiv);
  54. this.headSearchTextDiv = new Element("div.headSearchTextDiv",{"styles":this.css.headSearchTextDiv}).inject(this.headSearchDiv);
  55. this.headSearchImg = new Element("img.headSearchImg",{
  56. "styles":this.css.headSearchImg,
  57. "src": this.path+"default/icons/search.png"
  58. }).inject(this.headSearchTextDiv);
  59. this.headSearchInput = new Element("input.headSearchInput",{
  60. "styles":this.css.headSearchInput,
  61. "placeholder":this.lp.head.searchText
  62. }).inject(this.headSearchTextDiv);
  63. this.headSearchInput.addEvents({
  64. "keyup":function(){
  65. if(this.headSearchInput.get("value")!=""){
  66. this.headSearchRemoveImg.setStyles({"display":"inline-block"})
  67. }
  68. }.bind(this)
  69. });
  70. this.headSearchRemoveImg = new Element("img.headSearchRemoveImg",{
  71. "styles":this.css.headSearchRemoveImg,
  72. "src": this.path+"default/icons/remove.png"
  73. }).inject(this.headSearchTextDiv);
  74. this.headSearchRemoveImg.addEvents({
  75. "click":function(){
  76. this.headSearchInput.set("value","")
  77. }.bind(this)
  78. });
  79. this.headSearchBottonDiv = new Element("div.headSearchBottonDiv",{
  80. "styles":this.css.headSearchBottonDiv,
  81. "text":this.lp.head.search
  82. }).inject(this.headSearchDiv);
  83. this.headBottonDiv = new Element("div.headBottonDiv",{"styles":this.css.headBottonDiv}).inject(this.headContentDiv);
  84. this.headNewBottonDiv = new Element("div.headNewBottonDiv",{
  85. "styles":this.css.headNewBottonDiv,
  86. "text" :this.lp.head.create
  87. }).inject(this.headBottonDiv);
  88. this.headNewBottonDiv.addEvents({
  89. "click":function(){
  90. MWF.xDesktop.requireApp("CRM", "CustomerEdit", function(){
  91. this.explorer = new MWF.xApplication.CRM.CustomerEdit(this, this.actions,{},{
  92. "isEdited":true,
  93. "isNew":true,
  94. "onReloadView" : function( ){
  95. //alert(JSON.stringify(data))
  96. this.reload();
  97. }.bind(this)
  98. });
  99. this.explorer.load();
  100. }.bind(this))
  101. }.bind(this)
  102. });
  103. this.headMoreBottonDiv = new Element("div.headMoreBottonDiv",{
  104. "styles":this.css.headMoreBottonDiv,
  105. "text" :this.lp.head.moreAction
  106. }).inject(this.headBottonDiv);
  107. this.headMoreBottonDiv.addEvents({
  108. "click":function(){
  109. }.bind(this)
  110. });
  111. this.headMoreImg = new Element("img.headMoreImg",{
  112. "styles": this.css.headMoreImg,
  113. "src" : this.path+"default/icons/arrow.png"
  114. }).inject(this.headMoreBottonDiv);
  115. },
  116. createToolBarContent:function(){
  117. },
  118. createCustomerContent:function(){
  119. if(this.contentListDiv) this.contentListDiv.destroy();
  120. this.contentListDiv = new Element("div.contentListDiv",{"styles":this.css.contentListDiv}).inject(this.rightContentDiv);
  121. if(this.contentListInDiv) this.contentListInDiv.destroy();
  122. this.contentListInDiv = new Element("div.contentListInDiv",{"styles":this.css.contentListInDiv}).inject(this.contentListDiv);
  123. this.bottomPageBar = new Element("div.bottomPageBar",{"styles":this.css.bottomPageBar}).inject(this.contentListDiv);
  124. this.loadView();
  125. this.view.node.addEvents({
  126. "scroll":function(e){
  127. this.view.nodeHead.setStyle("margin-left",(0-this.view.node.scrollLeft)+"px");
  128. }.bind(this)
  129. });
  130. },
  131. loadView : function(){
  132. this.view = new MWF.xApplication.CRM.Customer.View( this.contentListInDiv, this.app, this, {
  133. templateUrl : this.path+"customerView.json",
  134. pagingEnable : true,
  135. pagingPar : {
  136. position : ["bottom"],
  137. hasNextPage : false,
  138. hasReturn:false,
  139. currentPage : this.options.viewPageNum||1,
  140. countPerPage : 30,
  141. onPostLoad : function( pagingBar ){
  142. }.bind(this),
  143. onPageReturn : function( pagingBar ){
  144. }.bind(this)
  145. }
  146. },{lp:this.app.lp.customerView,css : this.css} );
  147. //this.view.filterData = { sectionId : "5a60743f-e074-43ad-86c1-87c88b125281" , withTopSubject : true };
  148. //this.view.pagingContainerTop = this.pagingBarTop;
  149. this.view.pagingContainerBottom = this.bottomPageBar;
  150. this.view.load();
  151. },
  152. resizeWindow:function(){
  153. var size = this.rightContentDiv.getSize();
  154. var rSize = this.headTitleDiv.getSize();
  155. var lSize = this.headBottonDiv.getSize();
  156. if(this.headSearchDiv){
  157. var x = this.headSearchDiv.getSize().x;
  158. this.headSearchDiv.setStyles({"margin-left":(size.x-rSize.x-lSize.x)/2-(x/2)+"px"});
  159. }
  160. if(this.contentListDiv)this.contentListDiv.setStyles({"height":(size.y-this.headContentDiv.getHeight()-2)+"px","width":(this.rightContentDiv.getWidth())+"px"});
  161. if(this.contentListInDiv)this.contentListInDiv.setStyles({"height":(this.contentListDiv.getHeight()-this.bottomPageBar.getHeight())+"px","width":(this.rightContentDiv.getWidth())+"px"});
  162. if(this.view && this.view.node){
  163. //alert(this.contentListInDiv.getHeight())
  164. this.view.node.setStyles({
  165. "height":(this.contentListInDiv.getHeight()-40)+"px",
  166. "width":this.rightContentDiv.getWidth()+"px"
  167. });
  168. }
  169. }
  170. });
  171. MWF.xApplication.CRM.Customer.View = new Class({
  172. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  173. load: function () {
  174. this.thWidthArr = [];
  175. this.initData();
  176. this.ayalyseTemplate();
  177. var nodeHead = this.nodeHead = new Element("div.viewHeadListNode",{
  178. "styles":this.css.viewHeadListNode
  179. }).inject(this.container);
  180. this.node = new Element("div.viewBodyNode", {
  181. "styles": this.css.viewBodyNode
  182. }).inject(this.container);
  183. if( this.options.scrollEnable ){
  184. this.setScroll();
  185. }
  186. this.getContentTemplateNode();
  187. this.createHeadNode();
  188. this.createViewNode();
  189. //this.initSortData();
  190. //this.createViewHead();
  191. this.createViewBody();
  192. },
  193. createHeadNode:function(){
  194. var _width = 0;
  195. this._width = 0;
  196. this.template.items.each(function (item,i) {
  197. var headItemNode = this.formatElement(this.nodeHead, item.head);
  198. if(item.head.width){
  199. headItemNode.setStyle("width",parseInt(item.head.width)+"px");
  200. _width = _width + parseInt(item.head.width);
  201. if(i==this.template.items.length-1){
  202. if(_width<this.explorer.contentListInDiv.getWidth()){
  203. this.lastTdWidth = this.explorer.contentListInDiv.getWidth()-_width+parseInt(item.head.width);
  204. headItemNode.setStyle("width",parseInt(this.explorer.contentListInDiv.getWidth()-_width+parseInt(item.head.width))+"px");
  205. headItemNode.set("width",this.lastTdWidth);
  206. this._width = this._width + this.lastTdWidth;
  207. }else{
  208. this.lastTdWidth = parseInt(item.head.width);
  209. this._width = this._width + parseInt(item.head.width);
  210. }
  211. }else{
  212. this._width = this._width + parseInt(item.head.width);
  213. }
  214. }
  215. }.bind(this));
  216. },
  217. _createDocument: function(data, index){
  218. return new MWF.xApplication.CRM.Customer.Document(this.viewNode, data, this.explorer, this, null, index);
  219. },
  220. _getCurrentPageData: function(callback, count, pageNum){
  221. this.clearBody();
  222. if(!count)count=30;
  223. if(!pageNum)pageNum = 1;
  224. var filter = this.filterData || {};
  225. //var filter = {};
  226. //this.app.createShade();
  227. this.explorer.actions.getCustomerListPage( pageNum, count, filter, function(json){
  228. if( !json.data )json.data = [];
  229. if( !json.count )json.count=0;
  230. this.app.destroyShade();
  231. if( callback )callback(json);
  232. }.bind(this))
  233. },
  234. _removeDocument: function(documentData, all){
  235. },
  236. _create: function(){
  237. },
  238. _openDocument: function( documentData,index ){
  239. documentData = {
  240. id:"5514a10e-0789-4289-a4b5-c54022075553"
  241. };
  242. MWF.xDesktop.requireApp("CRM", "CustomerRead", function(){
  243. this.customerRead = new MWF.xApplication.CRM.CustomerRead(this.explorer.contentListDiv,this.app, this.explorer,this.actions,{
  244. "width":1000,
  245. "onReloadView" : function(){
  246. //alert("reload list")
  247. //alert(this.currentPage)
  248. this.gotoPage(this.currentPage)
  249. //this.explorer.createCustomerContent();
  250. }.bind(this)
  251. } );
  252. this.customerRead.load(documentData);
  253. this.explorer.formContentArr.push(this.customerRead);
  254. this.explorer.formMarkArr.push(this.customerRead.formMaskNode);
  255. }.bind(this));
  256. },
  257. _queryCreateViewNode: function(){
  258. },
  259. _postCreateViewNode: function( viewNode ){
  260. this.viewNode.set("width",this._width+"px");
  261. },
  262. _queryCreateViewHead:function(){
  263. },
  264. _postCreateViewHead: function( headNode ){
  265. }
  266. });
  267. MWF.xApplication.CRM.Customer.Document = new Class({
  268. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  269. _queryCreateDocumentNode:function( itemData ){
  270. },
  271. _postCreateDocumentNode: function( itemNode, itemData ){
  272. this.view.template.items.each(function (item,i) {
  273. if(item.head.width){
  274. itemNode.getElements("td")[i].set("width",item.head.width);
  275. }
  276. if(i == itemNode.getElements("td").length-1){
  277. itemNode.getElements("td")[i].set("width",this.view.lastTdWidth);
  278. }
  279. }.bind(this));
  280. },
  281. open: function (e) {
  282. this.view._openDocument(this.data, this.index);
  283. },
  284. edit : function(){
  285. var appId = "ForumDocument"+this.data.id;
  286. if (this.app.desktop.apps[appId]){
  287. this.app.desktop.apps[appId].setCurrent();
  288. }else {
  289. this.app.desktop.openApplication(null, "ForumDocument", {
  290. "sectionId" : this.data.sectionId,
  291. "id" : this.data.id,
  292. "appId": appId,
  293. "isEdited" : true,
  294. "isNew" : false,
  295. "index" : this.index
  296. });
  297. }
  298. }
  299. })
  300. //
  301. //MWF.xApplication.CRM.Customer.View = new Class({
  302. // Extends: MWF.xApplication.Template.Explorer.ComplexView,
  303. //
  304. // _createDocument: function(data){
  305. // return new MWF.xApplication.CRM.Customer.Document(this.viewNode, data, this.explorer, this);
  306. // },
  307. //
  308. // _getCurrentPageData: function(callback, count){
  309. // var category = this.category = this.options.category;
  310. //
  311. // if (!count)count = 20;
  312. // var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  313. //
  314. // if(id=="(0)")this.app.createShade();
  315. //
  316. // var filter = this.options.filterData || {};
  317. //
  318. // this.actions.getCustomerListNext(id, count, filter, function (json) {
  319. // if (callback)callback(json);
  320. // this.app.destroyShade();
  321. // }.bind(this));
  322. //
  323. // },
  324. // _create: function(){
  325. //
  326. // },
  327. // _openDocument: function( documentData ){
  328. //
  329. // //if(this.customerRead){
  330. // // this.customerRead.load(documentData)
  331. // //}else{
  332. // MWF.xDesktop.requireApp("CRM", "CustomerRead", function(){
  333. // this.customerRead = new MWF.xApplication.CRM.CustomerRead(this.explorer.contentListDiv,this.app, this.explorer,this.actions,{
  334. // "width":1000,
  335. // "onReloadView" : function(){
  336. // this.explorer.reloadCustomerView();
  337. // }.bind(this)
  338. // } );
  339. // this.customerRead.load(documentData);
  340. // this.explorer.formContentArr.push(this.customerRead);
  341. // this.explorer.formMarkArr.push(this.customerRead.formMaskNode);
  342. //
  343. // }.bind(this));
  344. // //}
  345. //
  346. // },
  347. // _queryCreateViewNode: function(){
  348. //
  349. // },
  350. // _postCreateViewNode: function( viewNode ){
  351. //
  352. // },
  353. // _queryCreateViewHead:function(){
  354. //
  355. // },
  356. // _postCreateViewHead: function( headNode ){
  357. //
  358. // }
  359. //
  360. //});
  361. //
  362. //MWF.xApplication.CRM.Customer.Document = new Class({
  363. // Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  364. //
  365. // "viewActionReturn":function(){
  366. // return false
  367. // }
  368. //
  369. //});