Contacts.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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.Contacts = 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.contact;
  17. this.path = "/x_component_CRM/$Contacts/";
  18. this.loadCss();
  19. this.actions = actions;
  20. this.node = $(node);
  21. },
  22. loadCss: function () {
  23. this.cssPath = "/x_component_CRM/$Contacts/" + 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", "ContactsEdit", function(){
  91. this.explorer = new MWF.xApplication.CRM.ContactsEdit(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. var size = this.rightContentDiv.getSize();
  124. if(this.contentListDiv)this.contentListDiv.setStyles({"height":(size.y-this.headContentDiv.getHeight()-8)+"px"});
  125. if(this.contentListInDiv)this.contentListInDiv.setStyles({"height":this.contentListDiv.getHeight()+"px","width":"100%"});
  126. if(this.contactsView) delete this.contactsView;
  127. var templateUrl = this.path+"contactsView.json";
  128. var filter = {};
  129. ////this.customerView = new MWF.xApplication.CRM.Customer.View(this.contentListInDiv, this.app, {lp : this.app.lp.curtomerView, css : this.css, actions : this.actions }, { templateUrl : templateUrl,filterData:filter} );
  130. this.contactsView = new MWF.xApplication.CRM.Contacts.View(
  131. this.contentListInDiv,
  132. this.openDiv,
  133. this.app,
  134. this,
  135. { templateUrl : templateUrl,filterData:filter},
  136. {
  137. lp:this.app.lp.contactsView
  138. }
  139. );
  140. this.contactsView.load();
  141. },
  142. resizeWindow:function(){
  143. var size = this.rightContentDiv.getSize();
  144. var rSize = this.headTitleDiv.getSize();
  145. var lSize = this.headBottonDiv.getSize();
  146. if(this.headSearchDiv){
  147. var x = this.headSearchDiv.getSize().x;
  148. this.headSearchDiv.setStyles({"margin-left":(size.x-rSize.x-lSize.x)/2-(x/2)+"px"});
  149. }
  150. //alert(JSON.stringify(size))
  151. if(this.contentListDiv)this.contentListDiv.setStyles({"height":(size.y-this.headContentDiv.getHeight()-8)+"px"});
  152. if(this.contentListInDiv)this.contentListInDiv.setStyles({"height":this.contentListDiv.getHeight()+"px"});
  153. }
  154. });
  155. MWF.xApplication.CRM.Contacts.View = new Class({
  156. Extends: MWF.xApplication.CRM.Template.ComplexView,
  157. _createDocument: function(data){
  158. return new MWF.xApplication.CRM.Clue.Document(this.viewNode, data, this.explorer, this);
  159. },
  160. _getCurrentPageData: function(callback, count, page, searchText){
  161. var category = this.category = this.options.category;
  162. if (!count)count = 15;
  163. if (!page)page = 1;
  164. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  165. //if(id=="(0)")this.app.createShade();
  166. var filter = this.options.filterData || {};
  167. if(searchText){
  168. filter = {
  169. key:searchText
  170. };
  171. }
  172. debugger
  173. this.actions.getContactsListPage(page, count, filter, function (json) {
  174. debugger
  175. if (callback)callback(json);
  176. }.bind(this));
  177. },
  178. _create: function(){
  179. },
  180. _openDocument: function(openId ,openName){
  181. /*MWF.xDesktop.requireApp("CRM", "ClueEdit", function(){
  182. this.explorer = new MWF.xApplication.CRM.ClueEdit(this, this.actions,{},{
  183. "clueId":clueId,
  184. "onReloadView" : function( ){
  185. //alert(JSON.stringify(data))
  186. this.reload();
  187. }.bind(this)
  188. });
  189. this.explorer.load();
  190. }.bind(this))*/
  191. MWF.xDesktop.requireApp("CRM", "ContactsOpen", function(){
  192. this.explorer = new MWF.xApplication.CRM.ContactsOpen(this, this.actions,{},{
  193. "openId":openId,
  194. "openName":openName,
  195. "openType":"single",
  196. "onReloadView" : function( ){
  197. //alert(JSON.stringify(data))
  198. this.reload();
  199. }.bind(this)
  200. });
  201. this.explorer.load();
  202. }.bind(this))
  203. },
  204. _openOtherDocument: function(openId ,openName){
  205. MWF.xDesktop.requireApp("CRM", "CustomerOpen", function(){
  206. this.explorer = new MWF.xApplication.CRM.CustomerOpen(this, this.actions,{},{
  207. "openId":openId,
  208. "openName":openName,
  209. "onReloadView" : function( ){
  210. //alert(JSON.stringify(data))
  211. this.reload();
  212. }.bind(this)
  213. });
  214. this.explorer.load();
  215. }.bind(this))
  216. },
  217. _queryCreateViewNode: function(){
  218. },
  219. _postCreateViewNode: function( viewNode ){
  220. },
  221. _queryCreateViewHead:function(){
  222. },
  223. _postCreateViewHead: function( headNode ){
  224. }
  225. });
  226. MWF.xApplication.CRM.Contacts.Document = new Class({
  227. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  228. _queryCreateDocumentNode:function( itemData ){
  229. },
  230. _postCreateDocumentNode: function( itemNode, itemData ){
  231. this.view.template.items.each(function (item,i) {
  232. if(item.head.width){
  233. itemNode.getElements("td")[i].set("width",item.head.width);
  234. }
  235. if(i == itemNode.getElements("td").length-1){
  236. itemNode.getElements("td")[i].set("width",this.view.lastTdWidth);
  237. }
  238. }.bind(this));
  239. },
  240. open: function (e) {
  241. this.view._openDocument(this.data, this.index);
  242. },
  243. edit : function(){
  244. var appId = "ForumDocument"+this.data.id;
  245. if (this.app.desktop.apps[appId]){
  246. this.app.desktop.apps[appId].setCurrent();
  247. }else {
  248. this.app.desktop.openApplication(null, "ForumDocument", {
  249. "sectionId" : this.data.sectionId,
  250. "id" : this.data.id,
  251. "appId": appId,
  252. "isEdited" : true,
  253. "isNew" : false,
  254. "index" : this.index
  255. });
  256. }
  257. }
  258. })
  259. //
  260. //MWF.xApplication.CRM.Customer.View = new Class({
  261. // Extends: MWF.xApplication.Template.Explorer.ComplexView,
  262. //
  263. // _createDocument: function(data){
  264. // return new MWF.xApplication.CRM.Customer.Document(this.viewNode, data, this.explorer, this);
  265. // },
  266. //
  267. // _getCurrentPageData: function(callback, count){
  268. // var category = this.category = this.options.category;
  269. //
  270. // if (!count)count = 20;
  271. // var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  272. //
  273. // if(id=="(0)")this.app.createShade();
  274. //
  275. // var filter = this.options.filterData || {};
  276. //
  277. // this.actions.getCustomerListNext(id, count, filter, function (json) {
  278. // if (callback)callback(json);
  279. // this.app.destroyShade();
  280. // }.bind(this));
  281. //
  282. // },
  283. // _create: function(){
  284. //
  285. // },
  286. // _openDocument: function( documentData ){
  287. //
  288. // //if(this.customerRead){
  289. // // this.customerRead.load(documentData)
  290. // //}else{
  291. // MWF.xDesktop.requireApp("CRM", "CustomerRead", function(){
  292. // this.customerRead = new MWF.xApplication.CRM.CustomerRead(this.explorer.contentListDiv,this.app, this.explorer,this.actions,{
  293. // "width":1000,
  294. // "onReloadView" : function(){
  295. // this.explorer.reloadCustomerView();
  296. // }.bind(this)
  297. // } );
  298. // this.customerRead.load(documentData);
  299. // this.explorer.formContentArr.push(this.customerRead);
  300. // this.explorer.formMarkArr.push(this.customerRead.formMaskNode);
  301. //
  302. // }.bind(this));
  303. // //}
  304. //
  305. // },
  306. // _queryCreateViewNode: function(){
  307. //
  308. // },
  309. // _postCreateViewNode: function( viewNode ){
  310. //
  311. // },
  312. // _queryCreateViewHead:function(){
  313. //
  314. // },
  315. // _postCreateViewHead: function( headNode ){
  316. //
  317. // }
  318. //
  319. //});
  320. //
  321. //MWF.xApplication.CRM.Customer.Document = new Class({
  322. // Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  323. //
  324. // "viewActionReturn":function(){
  325. // return false
  326. // }
  327. //
  328. //});