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.
 
 
 
 
 
 

141 lines
4.3 KiB

  1. wn.ui.AppFrame = Class.extend({
  2. init: function(parent, title, module) {
  3. this.set_document_title = true;
  4. this.buttons = {};
  5. this.$w = $('<div></div>').appendTo(parent);
  6. this.$titlebar = $('<div class="appframe-titlebar">\
  7. <div class="appframe-marker"></div>\
  8. <span class="appframe-center">\
  9. <span class="appframe-title"></span>\
  10. <span class="appframe-subject"></span>\
  11. </span>\
  12. <span class="close" style="margin-top: 5px; margin-right: 7px;">&times;</span>\
  13. </div>').appendTo(this.$w);
  14. this.$w.find('.close').click(function() {
  15. window.history.back();
  16. })
  17. if(title) this.title(title);
  18. if(module) this.set_marker(module);
  19. },
  20. title: function(txt) {
  21. this.set_title(txt);
  22. },
  23. set_title: function(txt) {
  24. if(this.set_document_title)
  25. document.title = txt;
  26. this.$titlebar.find(".appframe-title").html(txt);
  27. },
  28. set_marker: function(module) {
  29. var color = wn.get_module_color(module);
  30. this.$titlebar.find(".appframe-marker")
  31. .css({
  32. "background-color": color
  33. });
  34. },
  35. add_tab: function(tab_name, opacity, click) {
  36. var span = $('<span class="appframe-tab"></span>')
  37. .html(tab_name).insertAfter(this.$titlebar.find(".close"));
  38. opacity && span.css("opacity", opacity);
  39. click && span.click(click);
  40. return span
  41. },
  42. add_module_tab: function(module) {
  43. this.add_tab('<span class="small-module-icons small-module-icons-'+
  44. module.toLowerCase()+'"></span>'+' <span>'
  45. + wn._(module) + "</span>", 0.7, function() {
  46. wn.set_route(erpnext.modules[module]);
  47. });
  48. },
  49. add_button: function(label, click, icon) {
  50. this.add_toolbar();
  51. args = { label: label, icon:'' };
  52. if(icon) {
  53. args.icon = '<i class="icon '+icon+'"></i>';
  54. }
  55. this.buttons[label] = $(repl('<button class="btn btn-small">\
  56. %(icon)s %(label)s</button>', args))
  57. .click(click)
  58. .appendTo(this.toolbar);
  59. return this.buttons[label];
  60. },
  61. add_help_button: function(txt) {
  62. this.add_toolbar();
  63. $('<button class="btn btn-small" style="float:right;" button-type="help">\
  64. <b>?</b></button>')
  65. .data('help-text', txt)
  66. .click(function() { msgprint($(this).data('help-text'), 'Help'); })
  67. .appendTo(this.toolbar);
  68. },
  69. clear_buttons: function() {
  70. this.toolbar && this.toolbar.empty();
  71. },
  72. add_toolbar: function() {
  73. if(!this.toolbar)
  74. this.$w.append('<div class="appframe-toolbar"></div>');
  75. this.toolbar = this.$w.find('.appframe-toolbar');
  76. },
  77. add_label: function(label) {
  78. return $("<span class='label'>"+label+" </span>").appendTo(this.toolbar);
  79. },
  80. add_select: function(label, options) {
  81. this.add_toolbar();
  82. return $("<select style='width: 100px;'>")
  83. .add_options(options).appendTo(this.toolbar);
  84. },
  85. add_data: function(label) {
  86. this.add_toolbar();
  87. return $("<input style='width: 100px;' placeholder='"+ label +"'>")
  88. .appendTo(this.toolbar);
  89. },
  90. add_date: function(label, date) {
  91. this.add_toolbar();
  92. return $("<input style='width: 80px;'>").datepicker({
  93. dateFormat: sys_defaults.date_format.replace("yyyy", "yy"),
  94. changeYear: true,
  95. }).val(dateutil.str_to_user(date) || "").appendTo(this.toolbar);
  96. },
  97. add_ripped_paper_effect: function(wrapper) {
  98. if(!wrapper) var wrapper = wn.container.page;
  99. var layout_main = $(wrapper).find('.layout-main');
  100. if(!layout_main.length) {
  101. layout_main = $(wrapper).find('.layout-main-section');
  102. }
  103. layout_main.css({"padding-top":"25px"});
  104. $('<div class="ripped-paper-border"></div>')
  105. .prependTo(layout_main)
  106. .css({"width": $(layout_main).width()});
  107. }
  108. });
  109. // parent, title, single_column
  110. // standard page with appframe
  111. wn.ui.make_app_page = function(opts) {
  112. if(opts.single_column) {
  113. $(opts.parent).html('<div class="layout-wrapper layout-wrapper-appframe">\
  114. <div class="layout-appframe"></div>\
  115. <div class="layout-main"></div>\
  116. </div>');
  117. } else {
  118. $(opts.parent).html('<div class="layout-wrapper layout-wrapper-background">\
  119. <div class="layout-appframe"></div>\
  120. <div class="layout-main-section"></div>\
  121. <div class="layout-side-section"></div>\
  122. <div class="clear"></div>\
  123. </div>');
  124. }
  125. opts.parent.appframe = new wn.ui.AppFrame($(opts.parent).find('.layout-appframe'));
  126. if(opts.set_document_title!==undefined)
  127. opts.parent.appframe.set_document_title = opts.set_document_title;
  128. if(opts.title) opts.parent.appframe.title(opts.title);
  129. if(opts.module) opts.parent.appframe.set_marker(opts.module);
  130. }