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.

dashboard.js 2.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. wn.ui.form.Dashboard = Class.extend({
  2. init: function(opts) {
  3. $.extend(this, opts);
  4. this.wrapper = $('<div class="form-dashboard row"></div>')
  5. .prependTo(this.frm.layout.wrapper);
  6. this.body = $('<div></div>').appendTo(this.wrapper);
  7. },
  8. reset: function() {
  9. this.wrapper.toggle(false);
  10. this.body.empty();
  11. this.headline = null;
  12. },
  13. set_headline: function(html) {
  14. if(!this.headline)
  15. this.headline =
  16. $('<div class="form-headline col col-lg-12">').prependTo(this.body);
  17. this.headline.html(html);
  18. this.wrapper.toggle(true);
  19. },
  20. set_headline_alert: function(text, alert_class, icon) {
  21. this.set_headline(repl('<div class="alert %(alert_class)s">%(icon)s%(text)s</div>', {
  22. "alert_class": alert_class || "",
  23. "icon": icon ? '<i class="'+icon+'" /> ' : "",
  24. "text": text
  25. }));
  26. },
  27. add_doctype_badge: function(doctype, fieldname) {
  28. if(wn.model.can_read(doctype)) {
  29. this.add_badge(wn._(doctype), function() {
  30. wn.route_options = {};
  31. wn.route_options[fieldname] = cur_frm.doc.name;
  32. wn.set_route("List", doctype);
  33. }).attr("data-doctype", doctype);
  34. }
  35. },
  36. add_badge: function(label, onclick) {
  37. var badge = $(repl('<div class="col col-lg-4">\
  38. <div class="alert alert-badge">\
  39. <a class="badge-link">%(label)s</a>\
  40. <span class="badge pull-right">-</span>\
  41. </div></div>', {label:label}))
  42. .appendTo(this.body)
  43. badge.find(".badge-link").click(onclick);
  44. this.wrapper.toggle(true);
  45. return badge.find(".alert-badge");
  46. },
  47. set_badge_count: function(data) {
  48. var me = this;
  49. $.each(data, function(doctype, count) {
  50. $(me.wrapper)
  51. .find(".alert-badge[data-doctype='"+doctype+"'] .badge")
  52. .html(cint(count));
  53. });
  54. },
  55. add_progress: function(title, percent) {
  56. var width = cint(percent) < 1 ? 1 : percent;
  57. var progress_class = "";
  58. if(width < 10)
  59. progress_class = "progress-bar-danger";
  60. if(width > 99.9)
  61. progress_class = "progress-bar-success";
  62. var progress_area = this.body.find(".progress-area");
  63. if(!progress_area.length) {
  64. progress_area = $('<div class="progress-area">').appendTo(this.body);
  65. }
  66. $(repl('<div class="progress-chart">\
  67. <h5>%(title)s</h5>\
  68. <div class="progress">\
  69. <div class="progress-bar %(progress_class)s" style="width: %(width)s%"></div>\
  70. </div>\
  71. </div>', {
  72. title:title,
  73. width: width,
  74. progress_class: progress_class
  75. })).appendTo(progress_area);
  76. var n_charts = progress_area.find(".progress-chart").length,
  77. cols = Math.floor(12 / n_charts);
  78. progress_area.find(".progress-chart")
  79. .removeClass().addClass("progress-chart col col-lg-" + cols);
  80. this.wrapper.toggle(true);
  81. }
  82. })