Guest User

Untitled

a guest
Oct 19th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. function showDialog(title, msg, url, name, post, callback, def, validate) {
  2. $('body').append(
  3. '<div id="dialog">' +
  4. '<div class="hd">' + title + '</div>' +
  5. '<div class="bd">' +
  6. '<form method="POST" action="' + url + '?' + $.param({ format: 'json' }) + '">' +
  7. '<label>' + msg + '</label>' +
  8. '<input type="text" name="' + (name || 'text') + '" />' +
  9. '</form>' +
  10. '</div>' +
  11. '</div>'
  12. );
  13.  
  14. if (def) { // Default text
  15. $('#dialog input:text').val(def);
  16. }
  17.  
  18. if (YAHOO.lang.isFunction(callback)) {
  19. callback = { success: callback };
  20. }
  21.  
  22. var handleSubmit = function() {
  23. this.submit();
  24. };
  25.  
  26. var handleCancel = function() {
  27. if (callback.cancel) {
  28. callback.cancel();
  29. }
  30.  
  31. this.destroy();
  32. };
  33.  
  34. var dialog = new YAHOO.widget.Dialog('dialog', {
  35. buttons: [
  36. { text: 'OK' , handler: handleSubmit, isDefault: true },
  37. { text: 'Cancel', handler: handleCancel }
  38. ],
  39. fixedcenter: true , modal : true, postdata: $.param(post || {}),
  40. width : '300px', zIndex: 1000
  41. });
  42.  
  43. dialog.callback = {
  44. success: function(o) {
  45. var data = $.parseJSON(o.responseText);
  46.  
  47. if (data.success) {
  48. callback.success(data);
  49. } else {
  50. if (callback.failure) {
  51. callback.failure(data);
  52. } else {
  53. showSimpleDialog(data.error, true);
  54. }
  55. }
  56.  
  57. dialog.destroy();
  58. }
  59. };
  60.  
  61. dialog.validate = function() { // Empty input not to be submitted, and Renaming
  62. var v = this.getData()[name].trim(); // Brief requires customized validate, @13175527
  63.  
  64. if (!v.length) {
  65. alert('This is a required field!');
  66. }
  67.  
  68. return v.length && (!validate || validate(v));
  69. };
  70.  
  71. dialog.render(document.body);
  72. }
Add Comment
Please, Sign In to add comment