// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // MIT License. See license.txt wn.provide("wn.messages") wn.messages.waiting = function(parent, msg, bar_percent) { if(!bar_percent) bar_percent = '100'; return $(repl('
\

%(msg)s

\
\
', { bar_percent: bar_percent, msg: msg })) .appendTo(parent); }; wn.throw = function(msg) { msgprint(msg); throw msg; } wn.confirm = function(message, ifyes, ifno) { var d = msgprint("

" + message + "

\

\ \ \

"); $(d.wrapper).find(".btn-yes").click(function() { d.hide(); ifyes && ifyes(); }); $(d.wrapper).find(".btn-no").click(function() { d.hide(); ifno && ifno(); }); } var msg_dialog=null; function msgprint(msg, title) { if(!msg) return; if(msg instanceof Array) { $.each(msg, function(i,v) { if(v) { msgprint(v); } }) return; } if(typeof(msg)!='string') msg = JSON.stringify(msg); // small message if(msg.substr(0,8)=='__small:') { show_alert(msg.substr(8)); return; } if(!msg_dialog) { msg_dialog = new wn.ui.Dialog({ title:"Message", onhide: function() { if(msg_dialog.custom_onhide) { msg_dialog.custom_onhide(); } msg_dialog.msg_area.empty(); } }); msg_dialog.msg_area = $('
') .appendTo(msg_dialog.body); } if(msg.search(/
|

|

  • /)==-1) msg = replace_newlines(msg); msg_dialog.set_title(title || 'Message') // append a
    if another msg already exists if(msg_dialog.msg_area.html()) msg_dialog.msg_area.append("
    "); msg_dialog.msg_area.append(msg); msg_dialog.show(); return msg_dialog; } // Floating Message function show_alert(txt, add_class) { if(!$('#dialog-container').length) { $('
    ').appendTo('body'); } if(!$('#alert-container').length) { $('
    ').appendTo('#dialog-container'); } var div = $('
    \ ×'+ txt +'
    ') .appendTo('#alert-container') div.find('.close').click(function() { $(this).parent().remove(); return false; }); div.delay(7000).fadeOut(500); return div; }