You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

746 lines
20 KiB

  1. /* ItemBrowserPage
  2. + this.my_page
  3. + this.page_layout (wn.PageLayout)
  4. + this.wrapper
  5. + this.body
  6. + ItemBrowser
  7. + this.wrapper
  8. + this.wtab
  9. + body
  10. + has_results
  11. + head
  12. + toolbar_area
  13. + no_result
  14. + loading_div
  15. + sidebar
  16. */
  17. ItemBrowserPage = function() {
  18. this.lists = {};
  19. this.dt_details = {};
  20. this.cur_list = null;
  21. this.my_page = page_body.add_page('ItemBrowser');
  22. this.wrapper = $a(this.my_page,'div');
  23. }
  24. // -------------------------------------------------
  25. ItemBrowserPage.prototype.show = function(dt, label, field_list) {
  26. var me = this;
  27. if(this.cur_list && this.cur_list.dt != dt) $dh(this.cur_list.layout.wrapper);
  28. if(!me.lists[dt]) {
  29. me.lists[dt] = new ItemBrowser(me.wrapper, dt, label, field_list);
  30. }
  31. me.cur_list = me.lists[dt];
  32. me.cur_list.show();
  33. page_body.change_to('ItemBrowser');
  34. }
  35. // -------------------------------------------------
  36. ItemBrowser = function(parent, dt, label, field_list) {
  37. var me = this;
  38. this.label = label ? label : dt;
  39. this.dt = dt;
  40. this.field_list = field_list;
  41. this.tag_filter_dict = {};
  42. this.items = [];
  43. this.cscript = {}; // dictionary for custom scripting
  44. // heading
  45. var l = get_doctype_label(dt);
  46. l = (l.toLowerCase().substr(-4) == 'list') ? l : (l + ' List')
  47. // make the layout
  48. this.layout = new wn.PageLayout({
  49. parent: parent,
  50. main_width: '75%',
  51. sidebar_width: '25%',
  52. heading: l
  53. })
  54. this.layout.no_records = $a($td(this.layout.wtab,0,0), 'div');
  55. // header (?)
  56. this.desc_area = $a(this.layout.head, 'div', 'field_description', '');
  57. $dh(this.layout.page_head.separator);
  58. // areas
  59. this.no_result_area = $a(this.layout.no_records, 'div','layout_wrapper',{fontSize:'14px', textAlign:'center', padding:'200px 0px'});
  60. // loading...
  61. this.layout.loading = $a($td(this.layout.wtab,0,0), 'div','layout_wrapper',{padding:'200px 0px', textAlign:'center', fontSize:'14px', color:'#444', display:'none'});
  62. this.layout.loading.innerHTML = 'Loading<img src="images/ui/button-load.gif" style="margin-bottom: -2px; margin-left: 8px">';
  63. // setup toolbar
  64. this.setup_toolbar();
  65. // setup list and sidebar
  66. this.setup_sidebar();
  67. }
  68. // one of "loading", "no_result", "main"
  69. ItemBrowser.prototype.show_area = function(area) {
  70. $ds(this.layout[area]);
  71. var al = ['loading','no_records','main'];
  72. for(var a in al) {
  73. if(al[a]!=area)
  74. $dh(this.layout[al[a]]);
  75. }
  76. }
  77. ItemBrowser.prototype.setup_sidebar = function() {
  78. var me = this;
  79. // table
  80. $y(this.layout.sidebar_area, {paddingTop:'53px'});
  81. // sidebar
  82. this.sidebar = new wn.widgets.PageSidebar(this.layout.sidebar_area, {
  83. sections: [
  84. {
  85. title: 'Top Tags',
  86. render: function(body) {
  87. new wn.widgets.TagCloud(body, me.dt, function(tag) { me.set_tag_filter(tag) });
  88. }
  89. }
  90. ]
  91. });
  92. }
  93. // setup the toolbar and archiving and deleteing functionality
  94. ItemBrowser.prototype.setup_toolbar = function() {
  95. var me = this;
  96. var parent = this.layout.toolbar_area
  97. // toolbar
  98. this.main_toolbar = $a(parent, 'div', '', {padding: '3px', backgroundColor:'#EEE'});
  99. $br(this.main_toolbar, '3px'); $gr(this.main_toolbar, '#DDD', '#CCC');
  100. this.sub_toolbar = $a(parent, 'div', '', {marginBottom:'7px', padding: '3px', textAlign:'right', fontSize:'11px', color:'#444'});
  101. // archives label
  102. this.archives_label = $a(parent, 'div', 'help_box_big',{display:'none'},'Showing from Archives');
  103. var span = $a(this.archives_label, 'span', 'link_type', {marginLeft:'8px'}, 'Show Active');
  104. span.onclick = function() { me.show_archives.checked = 0; me.show_archives.onclick(); }
  105. this.trend_area = $a(parent, 'div', '', {marginBottom:'16px', padding: '4px', backgroundColor:'#EEF', border: '1px solid #CCF', display:'none'});
  106. $br(this.trend_area, '5px');
  107. // tag filters
  108. this.tag_filters = $a(parent, 'div', '', {marginBottom:'8px', display:'none', padding:'6px 8px 8px 8px', backgroundColor:'#FFD'});
  109. var span = $a(this.tag_filters,'span','',{marginRight:'4px',color:'#444'}); span.innerHTML = '<i>Showing for:</i>';
  110. this.tag_area = $a(this.tag_filters, 'span');
  111. // select all area
  112. var div = $a(parent, 'div', '', {margin:'3px 5px'});
  113. var chk = $a_input(div, 'checkbox');
  114. var lab = $a(div, 'span', '', {marginLeft:'9px'}, 'Select All');
  115. chk.onclick = function() {
  116. for(var i=0; i<me.items.length; i++) {
  117. me.items[i].check.checked = this.checked;
  118. me.items[i].check.onclick();
  119. }
  120. }
  121. this.select_all = chk;
  122. }
  123. // -------------------------------------------------
  124. ItemBrowser.prototype.make_checkbox = function(status, checked) {
  125. var me = this;
  126. var chk = $a_input(this.sub_toolbar, 'checkbox');
  127. var lab = $a(this.sub_toolbar, 'span', '', {marginRight:'8px'}, 'Show ' + status);
  128. chk.onclick = function() { me.run(); }
  129. chk.checked = checked;
  130. this['check_'+status] = chk;
  131. }
  132. ItemBrowser.prototype.get_status_check = function() {
  133. ret = [];
  134. if(this.check_Draft.checked) ret.push(0);
  135. if(this.check_Submitted.checked) ret.push(1);
  136. if(this.check_Cancelled.checked) ret.push(2);
  137. if(!ret.length) {
  138. msgprint('Atleast of Draft, Submitted or Cancelled must be checked!');
  139. return
  140. }
  141. return ret;
  142. }
  143. ItemBrowser.prototype.make_toolbar = function() {
  144. var me = this;
  145. // description
  146. if(this.dt_details.description)this.desc_area.innerHTML = this.dt_details.description;
  147. // new button
  148. if(inList(profile.can_create, this.dt)) {
  149. this.new_button = $btn(this.main_toolbar, '+ New ' + get_doctype_label(this.dt), function() { newdoc(me.dt) }, {fontWeight:'bold',marginRight:'0px'}, 'green');
  150. }
  151. // archive, delete
  152. if(in_list(profile.can_write, this.dt)) {
  153. this.archive_btn = $btn(this.main_toolbar, 'Archive', function() { me.archive_items(); }, {marginLeft:'24px'});
  154. }
  155. if(this.dt_details.can_cancel) {
  156. this.delete_btn = $btn(this.main_toolbar, 'Delete', function() { me.delete_items(); });
  157. }
  158. if(this.archive_btn && this.delete_btn)
  159. $btn_join(this.archive_btn, this.delete_btn)
  160. // search box
  161. this.search_input = $a(this.main_toolbar, 'input', '', {width:'120px', marginLeft:'24px', border:'1px solid #AAA'});
  162. this.search_btn = $btn(this.main_toolbar, 'Search', function() { me.run(); }, {marginLeft:'4px'});
  163. // show hide filters
  164. this.filters_on = 0;
  165. this.filter_btn = $ln(this.main_toolbar, 'Show Filters', function() { me.show_filters(); }, {marginLeft:'24px'});
  166. // show hide trend
  167. //this.trend_on = 0; this.trend_loaded = 0;
  168. //this.trend_btn = $ln(this.main_toolbar, 'Show Activity', function() { me.show_activity(); }, {marginLeft:'24px'});
  169. // checks for show cancelled and show archived
  170. if(this.dt_details.submittable) {
  171. this.make_checkbox('Draft', 1)
  172. this.make_checkbox('Submitted', 1)
  173. this.make_checkbox('Cancelled', 0)
  174. }
  175. this.set_archiving();
  176. }
  177. // -------------------------------------------------
  178. ItemBrowser.prototype.set_archiving = function() {
  179. var me = this;
  180. this.show_archives = $a_input(this.sub_toolbar, 'checkbox');
  181. var lab = $a(this.sub_toolbar, 'span'); lab.innerHTML = 'Show Archives';
  182. this.show_archives.onclick = function() {
  183. if(this.checked) {
  184. if(me.archive_btn) me.archive_btn.innerHTML = 'Restore';
  185. $(me.archives_label).slideDown();
  186. } else {
  187. if(me.archive_btn) me.archive_btn.innerHTML = 'Archive';
  188. $(me.archives_label).slideUp();
  189. }
  190. me.run();
  191. }
  192. }
  193. // -------------------------------------------------
  194. ItemBrowser.prototype.show_filters = function() {
  195. if(this.filters_on) {
  196. $(this.lst.filter_wrapper).slideUp();
  197. this.filters_on = 0;
  198. this.filter_btn.innerHTML = 'Advanced Search';
  199. } else {
  200. $(this.lst.filter_wrapper).slideDown();
  201. this.filters_on = 1;
  202. this.filter_btn.innerHTML = 'Hide Filters';
  203. }
  204. }
  205. // -------------------------------------------------
  206. ItemBrowser.prototype.show_activity = function() {
  207. var me = this;
  208. if(this.trend_on) {
  209. $(this.trend_area).slideUp();
  210. me.trend_btn.innerHTML = 'Show Activity';
  211. me.trend_on = 0;
  212. } else {
  213. // show
  214. if(!this.trend_loaded) {
  215. // load the trend
  216. var callback = function(r,rt) {
  217. me.show_trend(r.message.trend);
  218. $(me.trend_area).slideDown();
  219. me.trend_btn.done_working();
  220. me.trend_btn.innerHTML = 'Hide Activity';
  221. me.trend_loaded = 1;
  222. me.trend_on = 1;
  223. }
  224. $c('webnotes.widgets.menus.get_trend', {'dt':this.dt}, callback);
  225. me.trend_btn.set_working();
  226. } else {
  227. // slide up and dwon
  228. $(this.trend_area).slideDown();
  229. me.trend_btn.innerHTML = 'Hide Activity';
  230. me.trend_on = 1;
  231. }
  232. }
  233. }
  234. // -------------------------------------------------
  235. ItemBrowser.prototype.show = function(onload) {
  236. $ds(this.layout.wrapper);
  237. if(onload) this.cscript.onload = onload
  238. if(this.loaded && this.lst.n_records) return;
  239. this.show_area('loading');
  240. var me = this;
  241. var callback = function(r, rt) {
  242. if(r.message == 'Yes') {
  243. if(!me.loaded) {
  244. me.load_details();
  245. } else {
  246. me.show_results();
  247. }
  248. } else {
  249. if(me.cscript.onload) me.cscript.onload(this);
  250. me.show_no_result();
  251. }
  252. }
  253. $c('webnotes.widgets.menus.has_result', {'dt': this.dt}, callback);
  254. }
  255. // -------------------------------------------------
  256. ItemBrowser.prototype.load_details = function() {
  257. var me = this;
  258. var callback = function(r,rt) {
  259. me.dt_details = r.message;
  260. if(r.message) {
  261. me.make_toolbar();
  262. me.make_the_list(me.dt, me.layout.body);
  263. // fire onload
  264. if(me.cscript.onload)
  265. me.cscript.onload(me);
  266. me.show_results();
  267. }
  268. }
  269. var fl = this.field_list ? this.field_list.split('\n') : [];
  270. $c('webnotes.widgets.menus.get_dt_details', {'dt': this.dt, 'fl': JSON.stringify(fl)}, callback);
  271. this.loaded = 1;
  272. }
  273. // -------------------------------------------------
  274. ItemBrowser.prototype.show_results = function() {
  275. this.show_area('main');
  276. set_title(get_doctype_label(this.label));
  277. }
  278. // -------------------------------------------------
  279. ItemBrowser.prototype.show_trend = function(trend) {
  280. var maxval = 0;
  281. for(var key in trend) { if(trend[key]>maxval) maxval = trend[key] };
  282. // head
  283. var div = $a(this.trend_area, 'div','',{marginLeft:'32px'}); div.innerHTML = 'Activity in last 30 days';
  284. var wrapper_tab = make_table(this.trend_area, 1, 2, '100%', ['20px',null], {padding:'2px 4px',fontSize:'10px',color:'#888'});
  285. // y-label
  286. var ylab_tab = make_table($td(wrapper_tab,0,0),2,1,'100%',['100%'],{verticalAlign:'top', textAlign:'right',height:'24px'});
  287. $td(ylab_tab,0,0).innerHTML = maxval;
  288. $y($td(ylab_tab,1,0),{verticalAlign:'bottom'});
  289. $td(ylab_tab,1,0).innerHTML = '0';
  290. // infogrid
  291. var tab = make_table($td(wrapper_tab,0,1), 1, 30, '100%', [],
  292. {width:10/3 + '%', border:'1px solid #DDD', height:'40px', verticalAlign:'bottom', textAlign:'center', padding:'2px', backgroundColor:'#FFF'});
  293. // labels
  294. var labtab = make_table($td(wrapper_tab,0,1), 1, 6, '100%', [],
  295. {width:100/6 + '%', border:'1px solid #EEF', height:'16px',color:'#888',textAlign:'right',fontSize:'10px'});
  296. for(var i=0; i<30; i++) {
  297. var div = $a($td(tab,0,29-i),'div','',{backgroundColor:'#4AC', width:'50%', margin:'auto', height:(trend[i+''] ? (trend[i+'']*100/maxval) : 0) + '%'});
  298. div.setAttribute('title', trend[i] + ' records');
  299. // date string
  300. if(i % 5 == 0) {
  301. $td(labtab,0,5-(i/5)).innerHTML = dateutil.obj_to_user(dateutil.add_days(new Date(), -i));
  302. $y($td(tab,0,i-1),{'backgroundColor':'#EEE'});
  303. }
  304. }
  305. $td(labtab,0,5).innerHTML = 'Today';
  306. }
  307. // -------------------------------------------------
  308. ItemBrowser.prototype.show_no_result = function() {
  309. this.show_area('no_records');
  310. this.no_result_area.innerHTML = repl('No %(dt)s found. <span class="link_type" onclick="newdoc(\'%(dt)s\')">Click here</span> to create your first %(dt)s!', {dt:get_doctype_label(this.dt)});
  311. set_title(get_doctype_label(this.label));
  312. }
  313. // -------------------------------------------------
  314. ItemBrowser.prototype.make_new = function(dt, label, field_list) {
  315. // make the list
  316. this.make_the_list(dt, this.layout.body);
  317. }
  318. // -------------------------------------------------
  319. ItemBrowser.prototype.add_search_conditions = function(q) {
  320. if(this.search_input.value) {
  321. q.conds += ' AND ' + q.table + '.name LIKE "%'+ this.search_input.value +'%"';
  322. }
  323. }
  324. // -------------------------------------------------
  325. ItemBrowser.prototype.add_tag_conditions = function(q) {
  326. var me = this;
  327. if(keys(me.tag_filter_dict).length) {
  328. var cl = [];
  329. for(var key in me.tag_filter_dict) {
  330. var val = key;
  331. var op = '=';
  332. var fn = me.tag_filter_dict[key].fieldname;
  333. fn = fn ? fn : '_user_tags';
  334. // conditions based on user tags
  335. if(fn=='docstatus')val=(key=='Draft'?'0':'1');
  336. else if(fn=='_user_tags'){ val='%,'+key + '%'; op=' LIKE '; }
  337. cl.push(q.table + '.`' + fn + '`'+op+'"' + val + '"');
  338. }
  339. if(cl)
  340. q.conds += ' AND ' + cl.join(' AND ') + ' ';
  341. }
  342. }
  343. // -------------------------------------------------
  344. ItemBrowser.prototype.make_the_list = function(dt, wrapper) {
  345. var me = this;
  346. var lst = new Listing(dt, 1);
  347. lst.dt = dt;
  348. lst.cl = this.dt_details.columns;
  349. lst.opts = {
  350. cell_style : {padding:'0px 2px'},
  351. alt_cell_style : {backgroundColor:'#FFFFFF'},
  352. hide_export : 1,
  353. hide_print : 1,
  354. hide_rec_label: 0,
  355. show_calc: 0,
  356. show_empty_tab : 0,
  357. show_no_records_label: 1,
  358. show_new: 0,
  359. show_report: 1,
  360. no_border: 1,
  361. append_records: 1,
  362. formatted: 1
  363. }
  364. if(user_defaults.hide_report_builder) lst.opts.show_report = 0;
  365. // build th query
  366. lst.is_std_query = 1;
  367. lst.get_query = function() {
  368. q = {};
  369. var fl = [];
  370. q.table = repl('`%(prefix)s%(dt)s`', {prefix:(me.show_archives.checked ? 'arc' : 'tab'), dt:this.dt});
  371. // columns
  372. for(var i=0;i<this.cl.length;i++) {
  373. if(!(me.show_archives && me.show_archives.checked && this.cl[i][0]=='_user_tags'))
  374. fl.push(q.table+'.`'+this.cl[i][0]+'`')
  375. }
  376. if(me.dt_details.submittable) {
  377. fl.push(q.table + '.docstatus');
  378. var tmp = me.get_status_check();
  379. if(!tmp) { this.query=null; return; }
  380. // docstatus conditions
  381. q.conds = q.table + '.docstatus in ('+ tmp.join(',') +') ';
  382. } else {
  383. q.conds = q.table + '.docstatus != 2'
  384. }
  385. // columns
  386. q.fields = fl.join(', ');
  387. // filter conditions
  388. me.add_tag_conditions(q);
  389. // filter conditions
  390. me.add_search_conditions(q);
  391. this.query = repl("SELECT %(fields)s FROM %(table)s WHERE %(conds)s", q);
  392. this.query_max = repl("SELECT COUNT(*) FROM %(table)s WHERE %(conds)s", q);
  393. if(me.show_archives.checked)
  394. this.prefix = 'arc';
  395. else
  396. this.prefix = 'tab'
  397. }
  398. // make the columns
  399. lst.colwidths=['100%']; lst.coltypes=['Data']; lst.coloptions = [''];
  400. // show cell
  401. lst.show_cell = function(cell, ri, ci, d) {
  402. me.items.push(new ItemBrowserItem(cell, d[ri], me));
  403. }
  404. lst.make(wrapper);
  405. // add the filters
  406. var sf = me.dt_details.filters;
  407. for(var i=0;i< sf.length;i++) {
  408. var fname = sf[i][0]; var label = sf[i][1]; var ftype = sf[i][2]; var fopts = sf[i][3];
  409. if(in_list(['Int','Currency','Float','Date'], ftype)) {
  410. lst.add_filter('From '+label, ftype, fopts, dt, fname, '>=');
  411. lst.add_filter('To '+label, ftype, fopts, dt, fname, '<=');
  412. } else {
  413. lst.add_filter(label, ftype, fopts, dt, fname, (in_list(['Data','Text','Link'], ftype) ? 'LIKE' : ''));
  414. }
  415. }
  416. $dh(lst.filter_wrapper);
  417. // default sort
  418. lst.set_default_sort('modified', 'DESC');
  419. this.lst = lst;
  420. lst.run();
  421. }
  422. // -------------------------------------------------
  423. ItemBrowser.prototype.run = function() {
  424. this.items = [];
  425. this.select_all.checked = false;
  426. this.lst.run();
  427. }
  428. // -------------------------------------------------
  429. ItemBrowser.prototype.get_checked = function() {
  430. var il = [];
  431. for(var i=0; i<this.items.length; i++) {
  432. if(this.items[i].check.checked) il.push([this.dt, this.items[i].dn]);
  433. }
  434. return il;
  435. }
  436. // -------------------------------------------------
  437. ItemBrowser.prototype.delete_items = function() {
  438. var me = this;
  439. if(confirm('This is PERMANENT action and you cannot undo. Continue?'))
  440. $c('webnotes.widgets.menus.delete_items', {'items': JSON.stringify(this.get_checked()) }, function(r, rt) { if(!r.exc) me.run(); })
  441. }
  442. // -------------------------------------------------
  443. ItemBrowser.prototype.archive_items = function() {
  444. var me = this;
  445. var arg = {
  446. 'action': this.show_archives.checked ? 'Restore' : 'Archive'
  447. ,'items': JSON.stringify(this.get_checked())
  448. }
  449. $c('webnotes.widgets.menus.archive_items', arg, function(r, rt) { if(!r.exc) me.run(); })
  450. }
  451. // -------------------------------------------------
  452. ItemBrowser.prototype.set_tag_filter = function(tag) {
  453. var me = this;
  454. // check if exists
  455. if(in_list(keys(me.tag_filter_dict), tag.label)) return;
  456. // create a tag in filters
  457. var filter_tag = new SingleTag({
  458. parent: me.tag_area,
  459. label: tag.label,
  460. dt: me.dt,
  461. color: tag.color
  462. });
  463. filter_tag.fieldname = tag.fieldname;
  464. // remove tag from filters
  465. filter_tag.remove = function(tag_remove) {
  466. $(tag_remove.body).fadeOut();
  467. delete me.tag_filter_dict[tag_remove.label];
  468. // hide everything?
  469. if(!keys(me.tag_filter_dict).length) {
  470. $(me.tag_filters).slideUp(); // hide
  471. }
  472. // run
  473. me.run();
  474. }
  475. // add to dict
  476. me.tag_filter_dict[tag.label] = filter_tag;
  477. $ds(me.tag_filters);
  478. // run
  479. me.run();
  480. }
  481. // ========================== ITEM ==================================
  482. function ItemBrowserItem(parent, det, ib) {
  483. this.wrapper = $a(parent, 'div');
  484. $y(this.wrapper, {borderTop:'1px solid #DDD'});
  485. this.tab = make_table(this.wrapper, 1, 2, '100%', ['24px', null]);
  486. this.body = $a($td(this.tab, 0, 1), 'div');
  487. this.link_area = $a(this.body, 'div')
  488. this.details_area = this.link_area // $a(this.body, 'div');
  489. this.det = det;
  490. this.ib = ib;
  491. this.dn = det[0];
  492. this.make_check();
  493. this.make_tags();
  494. this.make_details();
  495. this.add_timestamp();
  496. }
  497. // -------------------------------------------------
  498. ItemBrowserItem.prototype.make_check = function() {
  499. if(this.ib.archive_btn || this.ib.delete_btn) {
  500. var me = this;
  501. this.check = $a_input($td(this.tab, 0, 0), 'checkbox');
  502. this.check.onclick = function() {
  503. if(this.checked) {
  504. $y(me.wrapper, {backgroundColor:'#FFC'});
  505. } else {
  506. $y(me.wrapper, {backgroundColor:'#FFF'});
  507. }
  508. }
  509. }
  510. }
  511. // -------------------------------------------------
  512. ItemBrowserItem.prototype.make_details = function() {
  513. // link
  514. var me = this;
  515. var div = this.details_area;
  516. var span = $a(this.link_area, 'span', 'link_type', {fontWeight:'bold', marginRight: '7px'});
  517. span.innerHTML = me.dn;
  518. span.onclick = function() { loaddoc(me.ib.dt, me.dn, null, null, (me.ib.show_archives ? me.ib.show_archives.checked : null)); }
  519. var cl = me.ib.dt_details.columns;
  520. var tag_fields = me.ib.dt_details.tag_fields ? me.ib.dt_details.tag_fields.split(',') : [];
  521. for(var i=0;i<tag_fields.length;i++) tag_fields[i] = strip(tag_fields[i]);
  522. if(me.ib.dt_details.subject) {
  523. // if there is a subject mentioned in the
  524. // doctype, build the string based on the
  525. // subject string
  526. var det_dict = {};
  527. for(var i=0; i<cl.length; i++) {
  528. var fieldname = cl[i][0];
  529. det_dict[fieldname] = me.det[i] ? me.det[i] : '';
  530. // set tag (optionally)
  531. if(in_list(tag_fields, fieldname))
  532. me.taglist.add_tag(me.det[i], 1, fieldname);
  533. }
  534. // write the subject
  535. var s = repl(me.ib.dt_details.subject, det_dict);
  536. if(s.substr(0,5)=='eval:') s = eval(s.substr(5));
  537. $a(div, 'span', '', {color:'#444'}, s)
  538. } else {
  539. // old -style - based on search_fields!
  540. // properties
  541. var tmp = [];
  542. var first_property = 1;
  543. for(var i=3; i<me.det.length; i++) {
  544. if(cl[i] && cl[i][1] && me.det[i]) {
  545. // has status, group or type in the label
  546. if(cl[i][1].indexOf('Status') != -1 ||
  547. cl[i][1].indexOf('Group') != -1 ||
  548. cl[i][1].indexOf('Priority') != -1 ||
  549. cl[i][1].indexOf('Type') != -1) {
  550. me.taglist.add_tag(me.det[i], 1, cl[i][0], '#c0c0c0');
  551. } else {
  552. // separator
  553. if(!first_property) {
  554. var span = $a(div,'span'); span.innerHTML = ',';
  555. } else first_property = 0;
  556. // label
  557. var span = $a(div,'span','',{color:'#888'});
  558. span.innerHTML = ' ' + cl[i][1] + ': ';
  559. // value
  560. var span = $a(div,'span');
  561. $s(span,me.det[i],(cl[i][2]=='Link'?'Data':cl[i][2]), cl[i][3]);
  562. }
  563. }
  564. }
  565. }
  566. }
  567. // -------------------------------------------------
  568. ItemBrowserItem.prototype.make_tags = function() {
  569. // docstatus tag
  570. var docstatus = cint(this.det[this.det.length - 1]);
  571. // make custom tags
  572. var me = this;
  573. var tl = this.det[2] ? this.det[2].split(',') : [];
  574. var div = $a(this.body, 'div', '', {margin: '7px 0px'})
  575. this.taglist = new TagList(div, tl, this.ib.dt, this.dn, 0, function(tag) { me.ib.set_tag_filter(tag); });
  576. }
  577. // -------------------------------------------------
  578. ItemBrowserItem.prototype.add_timestamp = function() {
  579. // time
  580. var div = $a(this.body, 'div', '', {color:'#888', fontSize:'11px'});
  581. div.innerHTML = comment_when(this.det[1]);
  582. }