Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

105 wiersze
3.2 KiB

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