annotate Agendas/trunk/src/Agendas.Web/Scripts/subpanels-0.9.js @ 292:1408ac17cb64

Patrocinadores: Faltaba aplicar seguridad a la Api de Patrocinadores.
author juanjose.montesdeocaarbos
date Thu, 09 Feb 2012 08:40:38 -0300
parents c8f378272407
children
rev   line source
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
1 jQuery.fn.subpanel = function () {
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
2 var panel = $(this[0]);
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
3
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
4 var settings = arguments[0] || {};
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
5
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
6 var closeLink = null;
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
7 var openLink = null;
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
8 var main = null;
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
9 var loading = null;
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
10
285
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents: 224
diff changeset
11
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
12 this.create = function () {
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
13 // botón para abrir el panel
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
14 openLink = $('<a></a>').addClass('ajax-button ui-state-default ui-corner-all').click(this.open).appendTo(panel);
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
15
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
16 var openSpan = $('<span></span>').addClass('ui-icon ui-icon-plusthick').html('open').appendTo(openLink);
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
17
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
18 //boton para cerrar el panel
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
19 closeLink = $('<a></a>')
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
20 .addClass('ajax-button ui-state-default ui-corner-tr ui-corner-tl')
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
21 .css('display', 'none')
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
22 .click(this.close).appendTo(panel);
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
23 var closeSpan = $('<span></span>').addClass('ui-icon ui-icon-minusthick').html('close').appendTo(closeLink);
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
24
220
42a1068e73c8 corrección en subpanels para respetar (un poco mas) html según la w3c
nelopauselli
parents: 219
diff changeset
25 var body = $('body');
42a1068e73c8 corrección en subpanels para respetar (un poco mas) html según la w3c
nelopauselli
parents: 219
diff changeset
26
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
27 // panel principal
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
28 main = $('<div></div>')
285
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents: 224
diff changeset
29 // .addClass('ui-accordion')
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
30 .addClass('sp-main ui-widget-content ui-corner-bottom')
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
31 .width(settings.width || '400px')
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
32 .css('display', 'none')
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
33 .css('padding', '5px 5px 5px 5px')
220
42a1068e73c8 corrección en subpanels para respetar (un poco mas) html según la w3c
nelopauselli
parents: 219
diff changeset
34 .appendTo(body);
42a1068e73c8 corrección en subpanels para respetar (un poco mas) html según la w3c
nelopauselli
parents: 219
diff changeset
35
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
36 panel.show();
220
42a1068e73c8 corrección en subpanels para respetar (un poco mas) html según la w3c
nelopauselli
parents: 219
diff changeset
37
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
38 if (settings.created != undefined)
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
39 settings.created();
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
40 };
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
41
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
42 this.close = function () {
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
43 if (loading !== undefined && loading !== null) {
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
44 loading.abort();
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
45 settings.aborting();
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
46 }
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
47
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
48 $(this).hide();
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
49 openLink.show();
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
50 main.hide();
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
51 main.html('');
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
52
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
53 if (settings.closed != undefined)
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
54 settings.closed();
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
55
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
56 };
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
57
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
58 this.open = function () {
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
59 var o = openLink.offset();
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
60 var top = o.top + openLink.outerHeight();
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
61 var left = o.left;
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
62
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
63 //main.offset({ top: top, left: left });
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
64 main.css('top', top);
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
65 main.css('left', left);
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
66
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
67 $(this).hide();
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
68 closeLink.show();
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
69 main.show();
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
70
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
71 // div que contendrá el html del panel
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
72 var content = $('<div></div>')
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
73 .appendTo(main);
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
74
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
75 var imgdiv = $('<div></div>').css('text-align', 'center').css('padding-top', '10px').appendTo(content);
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
76 if (settings.imageLoding !== undefined) {
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
77 var img = $('<img />').attr('src', settings.imageLoding).attr('alt', 'loading...').appendTo(imgdiv);
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
78 }
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
79
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
80 // se invoca la acción con un GET para obtener el contenido del panel
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
81 loading = $.ajax({
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
82 url: settings.url,
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
83 cache: false,
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
84 success: function (data) {
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
85 loading = null;
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
86
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
87 // cuando se recibe el contenido del panel, lo agregamos al div contenedor
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
88 content.html(data);
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
89
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
90 // buscamos el form que contiene el panel
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
91 var form = $('form', content);
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
92
285
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents: 224
diff changeset
93 /*
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
94 if ($('h3', content).length == 0)
285
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents: 224
diff changeset
95 form.before('<h3><h3>');
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
96 $('h3', content).each(function() {
285
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents: 224
diff changeset
97 $(this).addClass('ui-accordion-header ui-helper-reset ui-state-active');
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
98 });
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
99
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
100 // Agregamos un div que va a contener el form
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
101 var body = $('<div></div>');
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
102 body.addClass('ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active');
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
103 form.wrap(body);
285
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents: 224
diff changeset
104 */
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
105
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
106 // modificamos el evento submit
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
107 form.submit(dopost);
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
108
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
109 if ($.validator != undefined)
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
110 $.validator.unobtrusive.parse(form);
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
111
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
112 $(':submit', form).each(function () { $(this).button(); });
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
113
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
114 // y seteamos el foco en el primer input
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
115 var nextInput = $("input:visible:first", form);
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
116 nextInput.focus();
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
117
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
118 if (settings.loaded != undefined)
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
119 settings.loaded();
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
120 },
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
121 error: function (xhr, text) {
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
122 loading = null;
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
123
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
124 if (xhr.status !== 0) {
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
125 content.html(xhr.responseText)
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
126 .addClass('ui-state-error');
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
127 }
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
128 else {
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
129 closeLink.click();
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
130 }
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
131 }
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
132 });
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
133 };
285
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents: 224
diff changeset
134
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
135 function dopost(event) {
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
136 // prevenimos que se ejecute el submit ya que lo haremos manualmente.
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
137 event.preventDefault();
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
138
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
139 var self = $(this);
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
140
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
141 // preguntamos si el formulario es validable y válido
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
142 var valid = true;
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
143 if (self.valid !== undefined)
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
144 valid = self.valid();
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
145
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
146 if (valid === undefined || valid) {
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
147 // tomamos la acción y serializamos el form
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
148 var action = self.attr("action");
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
149 var data = self.serialize();
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
150
285
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents: 224
diff changeset
151 if (typeof (console) != 'undefined' && console && console.log)
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents: 224
diff changeset
152 console.log(data);
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
153
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
154 // ejecutamos el POST
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
155 $.post(action, data, function (data) {
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
156 // cuando termina de ejecutarse el POST, ejecutamos la acción configurada
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
157 var r = true;
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
158 if (settings.success != undefined)
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
159 settings.success(data);
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
160
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
161 // si esta acción no devuelve false, cerramos el panel
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
162 if (r === undefined || r)
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
163 closeLink.click();
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
164 });
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
165 }
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
166 }
219
b9850b647a4e Agregando alta de ponente durante la carga del evento
nelopauselli
parents:
diff changeset
167 this.create();
224
de6d206bd5c3 Actualizando subpanels
nelopauselli
parents: 220
diff changeset
168 }