Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function showDialog(title, msg, url, name, post, callback, def, validate) {
- $('body').append(
- '<div id="dialog">' +
- '<div class="hd">' + title + '</div>' +
- '<div class="bd">' +
- '<form method="POST" action="' + url + '?' + $.param({ format: 'json' }) + '">' +
- '<label>' + msg + '</label>' +
- '<input type="text" name="' + (name || 'text') + '" />' +
- '</form>' +
- '</div>' +
- '</div>'
- );
- if (def) { // Default text
- $('#dialog input:text').val(def);
- }
- if (YAHOO.lang.isFunction(callback)) {
- callback = { success: callback };
- }
- var handleSubmit = function() {
- this.submit();
- };
- var handleCancel = function() {
- if (callback.cancel) {
- callback.cancel();
- }
- this.destroy();
- };
- var dialog = new YAHOO.widget.Dialog('dialog', {
- buttons: [
- { text: 'OK' , handler: handleSubmit, isDefault: true },
- { text: 'Cancel', handler: handleCancel }
- ],
- fixedcenter: true , modal : true, postdata: $.param(post || {}),
- width : '300px', zIndex: 1000
- });
- dialog.callback = {
- success: function(o) {
- var data = $.parseJSON(o.responseText);
- if (data.success) {
- callback.success(data);
- } else {
- if (callback.failure) {
- callback.failure(data);
- } else {
- showSimpleDialog(data.error, true);
- }
- }
- dialog.destroy();
- }
- };
- dialog.validate = function() { // Empty input not to be submitted, and Renaming
- var v = this.getData()[name].trim(); // Brief requires customized validate, @13175527
- if (!v.length) {
- alert('This is a required field!');
- }
- return v.length && (!validate || validate(v));
- };
- dialog.render(document.body);
- }
Add Comment
Please, Sign In to add comment