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.
 
 
 
 
 
 

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