Skip to content

Commit

Permalink
fix dialog2
Browse files Browse the repository at this point in the history
git-svn-id: https://plugs.googlecode.com/svn/trunk@218 912515bb-fe1b-d127-1567-e02edd584596
  • Loading branch information
limodou committed Jun 26, 2012
1 parent 4d4b121 commit b44a01c
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 26 deletions.
@@ -1,7 +1,13 @@
.modal { .modal {
display: none; display: none;
top: 20%; top: 20%;
margin: 0 0 0 -280px; margin: 0 0 0 -280px;
overflow: hidden;
}

.wide-modal {
width: 800px;
margin: 0 0 0 -400px;
} }


.modal .modal-header h3 { .modal .modal-header h3 {
Expand Down
Expand Up @@ -48,6 +48,15 @@
this.trigger("dialog2.content-update"); this.trigger("dialog2.content-update");
}, handle); }, handle);


this.__ajaxFormSuccessTrigger = $.proxy(function(data) {
if(options.ajaxFormOptions.onSuccess){
options.ajaxFormOptions.onSuccess.call(element, data);
}
this.trigger("dialog2.ajax-complete", data);
if(options.ajaxFormOptions.dataType != 'json')
this.trigger("dialog2.content-update");
}, handle);

this.__ajaxStartTrigger = $.proxy(function() { this.__ajaxStartTrigger = $.proxy(function() {
this.trigger("dialog2.ajax-start"); this.trigger("dialog2.ajax-start");
}, handle); }, handle);
Expand All @@ -67,12 +76,12 @@
this.__removeDialog = $.proxy(this.__remove, this); this.__removeDialog = $.proxy(this.__remove, this);


handle.bind("dialog2.ajax-start", function() { handle.bind("dialog2.ajax-start", function() {
dialog.options({buttons: options.autoAddCancelButton ? localizedCancelButton() : {}}); dialog.options({buttons: options.autoAddCancelButton ? localizedCancelButton() : null});
handle.parent().addClass("loading"); handle.parent().addClass("loading");
}); });


handle.bind("dialog2.content-update", function() { handle.bind("dialog2.content-update", function() {
dialog.__ajaxify(); dialog.__ajaxify(options);
dialog.__updateMarkup(); dialog.__updateMarkup();
dialog.__focus(); dialog.__focus();
}); });
Expand All @@ -83,7 +92,12 @@


// Apply options to make title and stuff shine // Apply options to make title and stuff shine
this.options(options); this.options(options);


//add load content process
if (options.url){
this.load(options.url);
}

// We will ajaxify its contents when its new // We will ajaxify its contents when its new
// aka apply ajax styles in case this is a inpage dialog // aka apply ajax styles in case this is a inpage dialog
handle.trigger("dialog2.content-update"); handle.trigger("dialog2.content-update");
Expand Down Expand Up @@ -166,6 +180,7 @@
this.__overlay = handle.parent().prev(".modal-backdrop"); this.__overlay = handle.parent().prev(".modal-backdrop");


this.__addFocusCatchers(parentHtml); this.__addFocusCatchers(parentHtml);

}, },


__addFocusCatchers: function(parentHandle) { __addFocusCatchers: function(parentHandle) {
Expand All @@ -179,7 +194,7 @@
__updateMarkup: function() { __updateMarkup: function() {
var dialog = this; var dialog = this;
var e = dialog.__handle; var e = dialog.__handle;

e.trigger("dialog2.before-update-markup"); e.trigger("dialog2.before-update-markup");


// New options for dialog // New options for dialog
Expand Down Expand Up @@ -231,7 +246,7 @@
/** /**
* Apply ajax specific dialog behavior to the dialogs contents * Apply ajax specific dialog behavior to the dialogs contents
*/ */
__ajaxify: function() { __ajaxify: function(options) {
var dialog = this; var dialog = this;
var e = this.__handle; var e = this.__handle;


Expand All @@ -246,19 +261,19 @@
// Make submitable for an ajax form // Make submitable for an ajax form
// if the jquery.form plugin is provided // if the jquery.form plugin is provided
if ($.fn.ajaxForm) { if ($.fn.ajaxForm) {
var options = { var opts = $.extend({
target: e, target: e,
success: dialog.__ajaxCompleteTrigger, success: dialog.__ajaxFormSuccessTrigger,
beforeSubmit: dialog.__ajaxStartTrigger, beforeSubmit: dialog.__ajaxStartTrigger,
beforeSend: dialog.__ajaxBeforeSend, beforeSend: dialog.__ajaxBeforeSend,
error: function() { error: function() {
throw dialogError("Form submit failed: " + $.makeArray(arguments)); throw dialogError("Form submit failed: " + $.makeArray(arguments));
} }
}; }, options.ajaxFormOptions || {});
$("form.ajax", e) $("form.ajax", e)
.removeClass("ajax") .removeClass("ajax")
.ajaxForm(options); .ajaxForm(opts);
} }


e.trigger("dialog2.after-ajaxify"); e.trigger("dialog2.after-ajaxify");
Expand All @@ -279,7 +294,9 @@
* *
* @param backwards whether to focus backwards or not * @param backwards whether to focus backwards or not
*/ */
__focus: function(backwards) { __focus: function(backwards, focus) {
if (!(focus ||this.options.autoFocus)) return;

var dialog = this.__handle; var dialog = this.__handle;


// Focus first focusable element in dialog // Focus first focusable element in dialog
Expand Down Expand Up @@ -310,7 +327,7 @@
* focusable element in it (e.g. a link or a button on the button bar). * focusable element in it (e.g. a link or a button on the button bar).
*/ */
focus: function() { focus: function() {
return this.__focus(); return this.__focus('first', true);
}, },


/** /**
Expand All @@ -324,6 +341,7 @@
overlay.hide(); overlay.hide();


dialog dialog
.trigger("dialog2.beforeClose")
.parent().hide().end() .parent().hide().end()
.trigger("dialog2.closed") .trigger("dialog2.closed")
.removeClass("opened"); .removeClass("opened");
Expand Down Expand Up @@ -389,7 +407,6 @@
*/ */
removeButton: function(name) { removeButton: function(name) {
var footer = this.__handle.siblings(".modal-footer"); var footer = this.__handle.siblings(".modal-footer");

footer footer
.find("a.btn") .find("a.btn")
.filter(function(i, e) {return $(e).text() == name;}) .filter(function(i, e) {return $(e).text() == name;})
Expand Down Expand Up @@ -494,7 +511,7 @@
this.load(options.content); this.load(options.content);
} }


delete options.buttons; //delete options.buttons;


options = $.extend(true, {}, storedOptions, options); options = $.extend(true, {}, storedOptions, options);
this.__handle.data("options", options); this.__handle.data("options", options);
Expand Down Expand Up @@ -657,7 +674,10 @@
showCloseHandle: true, showCloseHandle: true,
initialLoadText: "", initialLoadText: "",
closeOnEscape: true, closeOnEscape: true,
beforeSend: null beforeSend: null,
autoFocus: true,
url: null,
ajaxFormOptions: null
}; };


/*********************************************************************** /***********************************************************************
Expand Down
65 changes: 65 additions & 0 deletions plugs/ui/bootstrap/templates/inc_jquery_dialog2.html
@@ -1,5 +1,70 @@
{{use "jqdialog2"}} {{use "jqdialog2"}}
{{use "poshytip"}}
<script> <script>

common_ajaxForm_success = function(options){
return function(r){
var opts = {
success:null,
message: show_message,
done:null,
error:null,
message_type:'bootstrap'
};
if (typeof options === 'function'){
opts.success = options;
}else{
opts = $.extend(opts, options);
}
if (r.success){
opts.message(r.message||'');
if(opts.success) opts.success.call(this, r);
if(opts.done) opts.done.call(this, r);
}else{
if(opts.error) opts.error.call(this, r);
else{
if(opts.message_type == 'bootstrap'){
$('div.control-group').removeClass('error').find('.help-block.error').remove();
opts.message(r.message, 'error');
$.each(r.data, function(key, value){
var f, t;
f = '#div_field_' + key;
t = $(f).addClass('error');
t.find('.controls').append('<p class="help-block error">'+value+'</p>');
});
}else if(opts.message_type == 'tip'){
var t = $(this);
$('body').on('dialog2.beforeClose', t, function(e){
t.find('input, select, textarea').poshytip('hide');
});
t.find('input, select, textarea').poshytip('hide');
$.each(r.data, function(key, value){
var el = t.find('input[name='+key+'],select[name='+key+'],textarea[name='+key+']');
if (el.is(':hidden')){
el = el.parent();
}
$(el).poshytip({
className: 'tip-yellowsimple',
content: value,
showOn: 'none',
alignTo: 'target',
alignX: 'inner-left',
offsetX: 0,
offsetY: 5,
closeButton: true
});
$(el).poshytip('show');
$(el).focus(function(){
$(this).poshytip('hide');
});
});
}
}
}
};
}


$(function(){ $(function(){


$(document).controls(); $(document).controls();
Expand Down
3 changes: 2 additions & 1 deletion plugs/ui/jquery/jqutils/static/jqutils/jqrselect.js
Expand Up @@ -138,7 +138,8 @@
this.element.val(''); this.element.val('');
}, },
options:{ options:{
showRemoveable:true showRemoveable:true,
url:null
}, },
destroy: function() { destroy: function() {
this.input.remove(); this.input.remove();
Expand Down
@@ -1,6 +1,6 @@
.tip-darkgray { .tip-darkgray {
opacity:0.95; opacity:0.95;
z-index:1000; z-index:2000;
text-align:left; text-align:left;
text-shadow:#444 0 1px 1px; text-shadow:#444 0 1px 1px;
border:1px solid #888; border:1px solid #888;
Expand Down
@@ -1,5 +1,5 @@
.tip-green { .tip-green {
z-index:1000; z-index:2000;
text-align:left; text-align:left;
border:1px solid #bdde98; border:1px solid #bdde98;
padding:7px 10px; padding:7px 10px;
Expand Down
@@ -1,5 +1,5 @@
.tip-skyblue { .tip-skyblue {
z-index:1000; z-index:2000;
text-align:left; text-align:left;
padding:8px 10px; padding:8px 10px;
min-width:50px; min-width:50px;
Expand Down
@@ -1,6 +1,6 @@
.tip-twitter { .tip-twitter {
opacity:0.8; opacity:0.8;
z-index:1000; z-index:2000;
text-align:left; text-align:left;
border-radius:4px; border-radius:4px;
-moz-border-radius:4px; -moz-border-radius:4px;
Expand Down
@@ -1,5 +1,5 @@
.tip-violet { .tip-violet {
z-index:1000; z-index:2000;
text-align:left; text-align:left;
border:1px solid #afafaf; border:1px solid #afafaf;
padding:7px; padding:7px;
Expand Down
@@ -1,5 +1,5 @@
.tip-yellow { .tip-yellow {
z-index:1000; z-index:2000;
text-align:left; text-align:left;
border:1px solid #939393; border:1px solid #939393;
padding:7px; padding:7px;
Expand Down
@@ -1,5 +1,5 @@
.tip-yellowsimple { .tip-yellowsimple {
z-index:1000; z-index:2000;
text-align:left; text-align:left;
border:1px solid #c7bf93; border:1px solid #c7bf93;
border-radius:4px; border-radius:4px;
Expand Down

0 comments on commit b44a01c

Please sign in to comment.