Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

138 строки
4.2 KiB

  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. var msg_dialog;
  23. function msgprint(msg, title) {
  24. if(!msg) return;
  25. if(typeof(msg)!='string')
  26. msg = JSON.stringify(msg);
  27. // small message
  28. if(msg.substr(0,8)=='__small:') {
  29. show_alert(msg.substr(8)); return;
  30. }
  31. if(!msg_dialog) {
  32. msg_dialog = new wn.ui.Dialog({
  33. title:"Message",
  34. onhide: function() {
  35. msg_dialog.msg_area.empty();
  36. }
  37. });
  38. msg_dialog.msg_area = $('<div class="msgprint">')
  39. .appendTo(msg_dialog.body);
  40. }
  41. if(msg.search(/<br>|<p>/)==-1)
  42. msg = replace_newlines(msg);
  43. msg_dialog.set_title(title || 'Message')
  44. msg_dialog.msg_area.append(msg);
  45. msg_dialog.show();
  46. }
  47. /*
  48. function msgprint(msg, issmall, callback) {
  49. if(!msg) return;
  50. if(typeof(msg)!='string')
  51. msg = JSON.stringify(msg);
  52. if(issmall) { show_alert(msg); return; }
  53. // small message
  54. if(msg.substr(0,8)=='__small:') {
  55. show_alert(msg.substr(8));
  56. return;
  57. }
  58. if(!msg_dialog) {
  59. msg_dialog = new Dialog(500, 200, "Message");
  60. msg_dialog.make_body([['HTML','Msg']])
  61. msg_dialog.onhide = function() {
  62. msg_dialog.msg_area.innerHTML = '';
  63. $dh(msg_dialog.msg_icon);
  64. if(msg_dialog.custom_onhide) msg_dialog.custom_onhide();
  65. }
  66. $y(msg_dialog.rows['Msg'], {fontSize:'14px', lineHeight:'1.5em', padding:'16px'})
  67. var t = make_table(msg_dialog.rows['Msg'], 1, 2, '100%',['20px','250px'],{padding:'2px',verticalAlign: 'Top'});
  68. msg_dialog.msg_area = $td(t,0,1);
  69. msg_dialog.msg_icon = $a($td(t,0,0),'img');
  70. }
  71. // blur bg
  72. if(!msg_dialog.display) msg_dialog.show();
  73. // set message content
  74. var has_msg = msg_dialog.msg_area.innerHTML ? 1 : 0;
  75. var m = $a(msg_dialog.msg_area,'div','');
  76. if(has_msg)$y(m,{marginTop:'4px'});
  77. $dh(msg_dialog.msg_icon);
  78. if(msg.substr(0,6).toLowerCase()=='error:') {
  79. msg_dialog.msg_icon.src = 'images/lib/icons/error.gif'; $di(msg_dialog.msg_icon); msg = msg.substr(6);
  80. } else if(msg.substr(0,8).toLowerCase()=='message:') {
  81. msg_dialog.msg_icon.src = 'images/lib/icons/application.gif'; $di(msg_dialog.msg_icon); msg = msg.substr(8);
  82. } else if(msg.substr(0,3).toLowerCase()=='ok:') {
  83. msg_dialog.msg_icon.src = 'images/lib/icons/accept.gif'; $di(msg_dialog.msg_icon); msg = msg.substr(3);
  84. }
  85. if(msg.search(/<br>|<p>/)==-1)
  86. m.innerHTML = replace_newlines(msg);
  87. if(m.offsetHeight > 200) {
  88. $y(m, {height:'200px', width:'400px', overflow:'auto'})
  89. }
  90. msg_dialog.custom_onhide = callback;
  91. }*/
  92. // Floating Message
  93. var growl_area;
  94. function show_alert(txt, id) {
  95. if(!growl_area) {
  96. if(!$('#dialog-container').length) {
  97. $('<div id="dialog-container">').appendTo('body');
  98. }
  99. growl_area = $a($i('dialog-container'), 'div', '', {position:'fixed', bottom:'8px', right:'8px', width: '320px', zIndex:10});
  100. }
  101. var wrapper = $a(growl_area, 'div', '', {position:'relative'});
  102. var body = $a(wrapper, 'div', 'notice');
  103. // close
  104. var c = $a(body, 'i', 'icon-remove-sign', {cssFloat:'right', cursor: 'pointer'});
  105. $(c).click(function() { $dh(this.wrapper) });
  106. c.wrapper = wrapper;
  107. // text
  108. var t = $a(body, 'div', '', { color:'#FFF' });
  109. $(t).html(txt);
  110. if(id) { $(t).attr('id', id); }
  111. $(wrapper).hide().fadeIn(1000);
  112. }