EasyUI Forum
May 17, 2024, 09:20:08 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [PATCH] Extending $.messager: a patch and a question  (Read 9657 times)
Juan Antonio Martínez
Jr. Member
**
Posts: 68



View Profile
« on: August 24, 2014, 04:23:00 AM »

Hi all!
I need a sort of messager.prompt, but using radiobuttons instead of textbox
So edited jquery.easyui.min.js and added:
Code:
.....
win.children("input.messager-input").focus();
return win;
},
//JAMC
/* msg is { val:text } collection for each radio button */
radio: function(title, msg, fn) {
var str="";
$.each(msg,function(val,text){
str +='<br /><input type="radio" name="messager-radio" value="'+val+'">'+text+'\n';
});
 var content = '<div class="messager-icon messager-question"></div>'
                         + '<div>' + title + '</div>'
                         + '<br/>'
                         + str
                         + '<div style="clear:both;"/>';
 var buttons = {};
 buttons[$.messager.defaults.ok] = function(){
         win.window('close');
         if (fn){
      var val=$('input:radio[name="messager-radio"]:checked').val();
                 fn(val);
                 return false;
         }
 };
 buttons[$.messager.defaults.cancel] = function(){
         win.window('close');
         if (fn){
                 fn();
                 return false;
         }
 };
 // _27f: createDialog()
 var win= _27f(title,content,buttons);
 return win;
},
//END JAMC
progress:function(_28e){
var _28f={bar:function(){
....

This patch works fine for me, but seems a bit dirty because needs patching (obfuscated) library file

My Question: ¿Whats the right way (tm) to extend $.messager to add different dialog styles without patching easyui library?
Thanks in advance
Juan Antonio
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: August 24, 2014, 07:57:28 AM »

Try this:
Code:
(function($){
function createDialog(title, content, buttons){
var win = $('<div class="messager-body"></div>').appendTo('body');
win.append(content);
if (buttons){
var tb = $('<div class="messager-button"></div>').appendTo(win);
for(var label in buttons){
$('<a></a>').attr('href', 'javascript:void(0)').text(label)
.css('margin-left', 10)
.bind('click', eval(buttons[label]))
.appendTo(tb).linkbutton();
}
}
win.window({
title: title,
noheader: (title?false:true),
width: 300,
height: 'auto',
modal: true,
collapsible: false,
minimizable: false,
maximizable: false,
resizable: false,
onClose: function(){
setTimeout(function(){
win.window('destroy');
}, 100);
}
});
win.window('window').addClass('messager-window');
win.children('div.messager-button').children('a:first').focus();
return win;
}
$.messager.radio = function(title, msg, fn){
var str="";
$.each(msg,function(val,text){
str +='<br /><input type="radio" name="messager-radio" value="'+val+'">'+text+'\n';
});
var content = '<div class="messager-icon messager-question"></div>'
                         + '<div>' + title + '</div>'
                         + '<br/>'
                         + str
                         + '<div style="clear:both;"/>';
var buttons = {};
buttons[$.messager.defaults.ok] = function(){
         win.window('close');
         if (fn){
      var val=$('input:radio[name="messager-radio"]:checked').val();
                 fn(val);
                 return false;
         }
};
buttons[$.messager.defaults.cancel] = function(){
         win.window('close');
         if (fn){
                 fn();
                 return false;
         }
};
var win = createDialog(title,content,buttons);
win.children('input.messager-input').focus();
return win;
}
})(jQuery);
Logged
Juan Antonio Martínez
Jr. Member
**
Posts: 68



View Profile
« Reply #2 on: August 24, 2014, 08:19:27 AM »

Works fine! Thanks

But still unsure if replicate creatDialog() in my code is a good practice... (what about easyui-lib updates ?)
Perhaps an idea for next releases is to provide a new messager.prompt implementing an user-definable text/radio/combo element as dialog body?

Thanks again for your time and your attention
Juan Antonio
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!