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.

page_header.js 3.1 KiB

13 years ago
13 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. //
  3. // MIT License (MIT)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a
  6. // copy of this software and associated documentation files (the "Software"),
  7. // to deal in the Software without restriction, including without limitation
  8. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. // and/or sell copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22. /* standard page header
  23. + wrapper
  24. + [table]
  25. + [r1c1]
  26. + main_head
  27. + sub_head
  28. + [r1c2]
  29. + close_btn
  30. + toolbar_area
  31. + tag_area
  32. + seperator
  33. */
  34. var def_ph_style = {
  35. wrapper: {marginBottom:'16px', backgroundColor:'#EEE'}
  36. ,main_heading: { }
  37. ,sub_heading: { marginBottom:'8px', color:'#555', display:'none' }
  38. ,separator: { borderTop:'1px solid #ddd' } // show this when there is no toolbar
  39. ,toolbar_area: { padding:'3px 0px', display:'none',borderBottom:'1px solid #ddd'}
  40. }
  41. function PageHeader(parent, main_text, sub_text) {
  42. this.wrapper = $a(parent,'div','page_header');
  43. this.close_btn = $a(this.wrapper, 'a', 'close', {}, '×');
  44. this.close_btn.onclick = function() { window.history.back(); };
  45. this.main_head = $a(this.wrapper, 'h1', '', def_ph_style.main_heading);
  46. this.sub_head = $a(this.wrapper, 'h4', '', def_ph_style.sub_heading);
  47. this.separator = $a(this.wrapper, 'div', '', def_ph_style.separator);
  48. this.toolbar_area = $a(this.wrapper, 'div', '', def_ph_style.toolbar_area);
  49. this.padding_area = $a(this.wrapper, 'div', '', {padding:'3px'});
  50. if(main_text) this.main_head.innerHTML = main_text;
  51. if(sub_text) this.sub_head.innerHTML = sub_text;
  52. this.buttons = {};
  53. this.buttons2 = {};
  54. }
  55. PageHeader.prototype.add_button = function(label, fn, bold, icon, green) {
  56. var tb = this.toolbar_area;
  57. if(this.buttons[label]) return;
  58. iconhtml = icon ? ('<i class="'+icon+'"></i> ') : '';
  59. var $button = $('<button class="btn">'+ iconhtml + label +'</button>')
  60. .click(fn)
  61. .appendTo(tb);
  62. if(green) {
  63. $button.addClass('btn-info');
  64. $button.find('i').addClass('icon-white');
  65. }
  66. if(bold) $button.css('font-weight', 'bold');
  67. this.buttons[label] = $button.get(0);
  68. $ds(this.toolbar_area);
  69. return this.buttons[label];
  70. }
  71. PageHeader.prototype.clear_toolbar = function() {
  72. this.toolbar_area.innerHTML = '';
  73. this.buttons = {};
  74. }
  75. PageHeader.prototype.make_buttonset = function() {
  76. $(this.toolbar_area).buttonset();
  77. }