25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

293 lines
7.8 KiB

  1. //
  2. // DocColumnView Tab (with mutliple doctypes)
  3. // features:
  4. // - create new
  5. // - view
  6. // - filter and show next
  7. // - special actions (Invite)
  8. //
  9. wn.widgets.DocColumnView = function(title, parent, items, opts) {
  10. this.columns = {};
  11. this.items = items;
  12. this.page_head = new PageHeader(parent, title);
  13. this.make_columns(items.length, parent);
  14. for(var i=0; i<items.length; i++) {
  15. var c = opts[items[i]];
  16. this.columns[items[i]] = new wn.widgets.dcvList(this, $td(this.tab, 0, i), items[i], c);
  17. }
  18. this.columns[items[0]].run();
  19. }
  20. wn.widgets.DocColumnView.prototype.make_columns = function(n, parent) {
  21. var cl = [];
  22. for(var i=0; i< n; i++) { cl.push(cint(100/n) + '%') }
  23. this.tab = make_table(parent, 1, n, '100%', cl)
  24. this.tab.className = 'dcv-tab';
  25. }
  26. wn.widgets.DocColumnView.prototype.refresh = function() {
  27. this.columns[this.items[0]].run();
  28. }
  29. //
  30. // wn.widgets.dcvList
  31. //
  32. wn.widgets.dcvList = function(dcv, parent, doctype, opts) {
  33. this.dcv = dcv;
  34. this.doctype = doctype;
  35. this.opts = opts;
  36. this.dtl = get_doctype_label(doctype);
  37. this.make_body(parent);
  38. this.selected_item = null;
  39. }
  40. // body
  41. wn.widgets.dcvList.prototype.make_body = function(parent) {
  42. this.make_toolbar(parent);
  43. this.make_search(parent);
  44. this.make_message(parent);
  45. this.make_list(parent);
  46. this.clear();
  47. }
  48. // new
  49. wn.widgets.dcvList.prototype.make_toolbar = function(parent) {
  50. var me = this;
  51. this.head = $a(parent, 'div', 'list2-head'); $gr(this.head, '#EEE', '#CCC');
  52. var t = make_table(this.head, 1, 2, '100%', ['60%', '40%'], {verticalAlign:'middle'});
  53. var span = $a($td(t,0,0), 'span', '', {cssFloat:'left'}, this.dtl);
  54. // refresh
  55. var refresh_icon = $a($td(t, 0, 0), 'div', 'wn-icon ic-playback_reload', {marginLeft:'7px', cssFloat:'left'});
  56. refresh_icon.onclick = function() { me.run(); }
  57. // new
  58. this.btn = $btn($td(t,0,1), '+ New', function() { me.make_new(); }, {fontWeight:'bold', cssFloat:'right'}, 'green');
  59. }
  60. // search
  61. wn.widgets.dcvList.prototype.make_search = function(parent) {
  62. var me = this;
  63. this.searchbar = $a(parent, 'div', 'list2-search');
  64. this.search_inp = $a_input(this.searchbar, 'text');
  65. // button
  66. this.search_btn = $a(this.searchbar, 'img', '', {cursor:'pointer', marginLeft:'8px', marginBottom:'-3px'});
  67. this.search_btn.src = 'images/icons/magnifier.png';
  68. this.search_btn.onclick = function() { me.run(); }
  69. }
  70. // make message
  71. wn.widgets.dcvList.prototype.make_message = function(parent) {
  72. // please select
  73. this.clear_message = $a(parent, 'div', 'help_box', {margin:'4px', display:'none'},
  74. (this.opts.filter_by ? ('Select ' + get_doctype_label(this.opts.filter_by[0]) + ' to see list') : ''));
  75. // no result
  76. this.no_result_message = $a(parent, 'div', 'help_box', {margin:'4px', display:'none'}, 'No ' + this.dtl + ' created yet!');
  77. }
  78. // create new
  79. wn.widgets.dcvList.prototype.make_new = function() {
  80. var me = this;
  81. newdoc(this.doctype, function(dn) {
  82. if(me.opts.filter_by) {
  83. var val = me.dcv.columns[me.opts.filter_by[0]].get_selected();
  84. if(val)
  85. locals[me.doctype][dn][me.opts.filter_by[1]] = val;
  86. }
  87. if(me.opts.set_values) {
  88. for(key in me.opts.set_values) {
  89. locals[me.doctype][dn][key] = me.opts.set_values[key]
  90. }
  91. }
  92. });
  93. }
  94. // clear
  95. wn.widgets.dcvList.prototype.clear = function() {
  96. $dh(this.lst_area);
  97. $ds(this.clear_message)
  98. $dh(this.no_result_message);
  99. this.clear_next();
  100. }
  101. // show list
  102. wn.widgets.dcvList.prototype.show_list = function() {
  103. $ds(this.lst_area);
  104. $dh(this.clear_message)
  105. $dh(this.no_result_message);
  106. }
  107. // no result
  108. wn.widgets.dcvList.prototype.show_no_result = function() {
  109. if(!this.search_inp.value) {
  110. $dh(this.lst_area);
  111. $dh(this.clear_message);
  112. $ds(this.no_result_message);
  113. }
  114. }
  115. // clear next
  116. wn.widgets.dcvList.prototype.clear_next = function() {
  117. if(this.opts.next_col && this.dcv.columns[this.opts.next_col]) this.dcv.columns[this.opts.next_col].clear();
  118. }
  119. // listing
  120. wn.widgets.dcvList.prototype.make_list = function(parent) {
  121. var me = this;
  122. this.lst_area = $a(parent, 'div', 'list2-list-area');
  123. this.lst = new Listing('Profiles',1);
  124. this.lst.opts.hide_refresh = 1; this.lst.opts.cell_style = {padding:'0px'};
  125. this.lst.colwidths = ['100%'];
  126. this.lst.get_query = function() {
  127. var q = me.build_query();
  128. this.query = q[0]; this.query_max = q[1];
  129. }
  130. this.lst.make(this.lst_area);
  131. this.lst.show_cell= function(cell, ri, ci, d) {
  132. new wn.widgets.dcvListItem(cell, d[ri], me);
  133. }
  134. this.lst.onrun = function() {
  135. me.show_list();
  136. me.clear_next();
  137. if(!me.lst.has_data()) me.show_no_result();
  138. }
  139. }
  140. wn.widgets.dcvList.prototype.run = function() {
  141. $dh(this.lst.results);
  142. this.lst.run();
  143. }
  144. //
  145. // build query from config
  146. //
  147. wn.widgets.dcvList.prototype.build_query = function() {
  148. var args = {
  149. fields: this.opts.show_fields.join(', '),
  150. doctype: this.doctype,
  151. cond: ''
  152. }
  153. var cl = this.build_search_conditions();
  154. cl = this.add_filter_condition(cl);
  155. if(cl.length) args.cond = ' AND ' + cl.join(' AND ');
  156. var query = repl('SELECT %(fields)s FROM `tab%(doctype)s` WHERE docstatus < 2 %(cond)s', args)
  157. var query_max = repl('SELECT COUNT(*) FROM `tab%(doctype)s` WHERE docstatus < 2 %(cond)s', args)
  158. //msgprint(query)
  159. return [query, query_max]
  160. }
  161. wn.widgets.dcvList.prototype.build_search_conditions = function() {
  162. var cl = new Array();
  163. if(this.opts.conditions) {
  164. for(var i=0;i<this.opts.conditions.length;i++) cl.push(this.opts.conditions);
  165. }
  166. if(this.search_inp.value && this.search_inp.value != 'Search') {
  167. for(var i=0; i<this.opts.search_fields.length; i++) {
  168. cl.push(repl('`%(field)s` LIKE "%(txt)s"', {
  169. field: this.opts.search_fields[i],
  170. txt:'%' + this.search_inp.value + '%'
  171. }));
  172. }
  173. }
  174. return cl;
  175. }
  176. wn.widgets.dcvList.prototype.add_filter_condition = function(cl) {
  177. // filter by (from prev column?)
  178. if(this.opts.filter_by) {
  179. cl.push(repl('`%(filter)s` = "%(val)s"', {
  180. filter: this.opts.filter_by[1],
  181. val:this.dcv.columns[this.opts.filter_by[0]].get_selected()
  182. }));
  183. }
  184. return cl;
  185. }
  186. //
  187. // get selected item
  188. //
  189. wn.widgets.dcvList.prototype.get_selected = function() {
  190. if(this.selected_item) return this.selected_item.det[0]; else return '';
  191. }
  192. //
  193. // List item
  194. //
  195. wn.widgets.dcvListItem = function(cell, det, list2) {
  196. this.det = det;
  197. this.list2 = list2;
  198. this.make_body(cell);
  199. this.show_text();
  200. this.show_more_info();
  201. }
  202. // body
  203. wn.widgets.dcvListItem.prototype.make_body = function(cell) {
  204. var me = this;
  205. this.body = $a(cell, 'div', 'list2-item-div')
  206. if(me.list2.opts.next_col) {
  207. this.make_with_icon();
  208. } else {
  209. this.content = this.body;
  210. }
  211. this.body.onclick = function() {
  212. me.select();
  213. if(me.list2.opts.next_col) me.list2.dcv.columns[me.list2.opts.next_col].run();
  214. }
  215. }
  216. // body with icon (right arrow)
  217. wn.widgets.dcvListItem.prototype.make_with_icon = function() {
  218. var t = make_table(this.body, 1, 2, '100%', ['','18px'])
  219. $y($td(t, 0, 1), {verticalAlign:'middle'})
  220. var img = $a($td(t, 0, 1), 'img'); img.src = 'images/icons/control_play.png';
  221. this.content = $td(t, 0, 0);
  222. }
  223. // body with text
  224. wn.widgets.dcvListItem.prototype.show_text = function() {
  225. var me = this;
  226. this.label = $a(this.content, 'div', 'list2-item-title', '', this.det[0]);
  227. var span = $a(this.label, 'span', 'link_type list2-edit-link', '', '[Edit]');
  228. span.onclick = function() {
  229. loaddoc(me.list2.doctype, me.det[0]);
  230. }
  231. }
  232. // additional fields
  233. wn.widgets.dcvListItem.prototype.show_more_info = function() {
  234. var det = this.det;
  235. if(det.length>1) {
  236. var l = [];
  237. for(var i=1; i< det.length; i++) { if(det[i] && det[i]!=det[0]) l.push(det[i]); }
  238. if(l.length)
  239. this.more_info = $a(this.content, 'div', 'list2-item-more-info', '', l.join(', '))
  240. }
  241. }
  242. // select
  243. wn.widgets.dcvListItem.prototype.select = function() {
  244. if(this.list2.selected_item) this.list2.selected_item.deselect();
  245. this.body.className = 'list2-item-div list2-item-selected';
  246. this.list2.selected_item = this;
  247. }
  248. // deselect
  249. wn.widgets.dcvListItem.prototype.deselect = function() {
  250. this.body.className = 'list2-item-div';
  251. }