您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

106 行
2.5 KiB

  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. wn.provide("wn.messages")
  4. wn.messages.waiting = function(parent, msg, bar_percent) {
  5. if(!bar_percent) bar_percent = '100';
  6. return $(repl('<div class="well" style="width: 63%; margin: 30px auto;">\
  7. <p style="text-align: center;">%(msg)s</p>\
  8. <div class="progress progress-striped active">\
  9. <div class="progress-bar progress-bar-info" style="width: %(bar_percent)s%"></div></div>', {
  10. bar_percent: bar_percent,
  11. msg: msg
  12. }))
  13. .appendTo(parent);
  14. };
  15. wn.throw = function(msg) {
  16. msgprint(msg);
  17. throw msg;
  18. }
  19. wn.confirm = function(message, ifyes, ifno) {
  20. var d = msgprint("<p>" + message + "</p>\
  21. <p style='text-align: right'>\
  22. <button class='btn btn-info btn-yes'>Yes</button>\
  23. <button class='btn btn-default btn-no'>No</button>\
  24. </p>");
  25. $(d.wrapper).find(".btn-yes").click(function() {
  26. d.hide();
  27. ifyes && ifyes();
  28. });
  29. $(d.wrapper).find(".btn-no").click(function() {
  30. d.hide();
  31. ifno && ifno();
  32. });
  33. }
  34. var msg_dialog=null;
  35. function msgprint(msg, title) {
  36. if(!msg) return;
  37. if(msg instanceof Array) {
  38. $.each(msg, function(i,v) {
  39. if(v) {
  40. msgprint(v);
  41. }
  42. })
  43. return;
  44. }
  45. if(typeof(msg)!='string')
  46. msg = JSON.stringify(msg);
  47. // small message
  48. if(msg.substr(0,8)=='__small:') {
  49. show_alert(msg.substr(8)); return;
  50. }
  51. if(!msg_dialog) {
  52. msg_dialog = new wn.ui.Dialog({
  53. title:"Message",
  54. onhide: function() {
  55. if(msg_dialog.custom_onhide) {
  56. msg_dialog.custom_onhide();
  57. }
  58. msg_dialog.msg_area.empty();
  59. }
  60. });
  61. msg_dialog.msg_area = $('<div class="msgprint">')
  62. .appendTo(msg_dialog.body);
  63. }
  64. if(msg.search(/<br>|<p>|<li>/)==-1)
  65. msg = replace_newlines(msg);
  66. msg_dialog.set_title(title || 'Message')
  67. // append a <hr> if another msg already exists
  68. if(msg_dialog.msg_area.html()) msg_dialog.msg_area.append("<hr>");
  69. msg_dialog.msg_area.append(msg);
  70. msg_dialog.show();
  71. return msg_dialog;
  72. }
  73. // Floating Message
  74. function show_alert(txt, add_class) {
  75. if(!$('#dialog-container').length) {
  76. $('<div id="dialog-container">').appendTo('body');
  77. }
  78. if(!$('#alert-container').length) {
  79. $('<div id="alert-container"></div>').appendTo('#dialog-container');
  80. }
  81. var div = $('<div class="alert alert-warning">\
  82. <a class="close">&times;</a>'+ txt +'</div>')
  83. .appendTo('#alert-container')
  84. div.find('.close').click(function() {
  85. $(this).parent().remove();
  86. return false;
  87. });
  88. div.delay(7000).fadeOut(500);
  89. return div;
  90. }