1 var SlideWindowClass = Class.create({
12 configurationObj: null,
20 widthNormal : '437px',
21 heightNormal : '325px',
29 containerSuffix : '-slide-window-container',
30 configurationWindows : 'div.configuration',
31 configurationProgress: 'div.configuration-progress',
32 contentItems : 'slide-window-element',
33 contentAlternatingItems : 'slide-window-element-alternating',
34 toolsButtonSuffix : '-slide-window-tools',
35 optionsButtonSuffix : '-slide-window-options',
36 actionsSuffix : '-slide-window-actions',
37 toolbarSuffix : '-slide-window-toolbar',
38 titleSuffix : '-slide-window-title'
41 initialize: function(windowId, data) {
42 if(typeof(windowId) == "undefined") {
46 this.windowId = windowId;
47 this.window = $(this.windowId + this.elements.containerSuffix);
48 this.tools = $(this.windowId + this.elements.toolsButtonSuffix);
49 this.options = $(this.windowId + this.elements.optionsButtonSuffix);
51 if(data.hasOwnProperty('showId')) {
52 this.showEl = $(data.showId);
54 alert('slide-window.js - "showId" property does not exists.');
58 if(data.hasOwnProperty('hideId')) {
59 this.hideEl = $(data.hideId);
61 alert('slide-window.js - "hideId" property does not exists.');
65 if(data.hasOwnProperty('fullSizeId')) {
66 this.fullSizeEl = $(data.fullSizeId);
68 alert('slide-window.js - "fullSizeId" property does not exists.');
72 if(data.hasOwnProperty('search')) {
73 this.search = $(data.search);
75 alert('slide-window.js - "search" property does not exists.');
81 objectExists: function(key) {
82 return this.objects.hasOwnProperty(key);
85 registerObj: function(key, obj) {
86 if(this.objectExists(key) === false) {
87 this.objects[key] = obj;
91 getObj: function(key) {
93 if(this.objectExists(key) === true) {
94 obj = this.objects[key];
99 setEvents: function() {
100 this.showEl.observe('click', function(){
104 this.hideEl.observe('click', function(){
108 this.fullSizeEl.observe('click', function(){
112 this.search.observe('keyup', function(){
116 this.tools.observe('click', function() {
117 this.toggleToolbar();
120 this.options.observe('click', function() {
121 this.toggleToolbar();
125 openWindow : function() {
126 this.hideOtherWindows();
127 Effect.toggle(this.window, 'slide', { duration: 0.3, afterFinish : function() {
128 this.normalSizeWindow();
133 closeWindow : function() {
134 Effect.toggle(this.window, 'slide', { duration: 0.3, afterFinish : function() {
140 resetSize : function() {
141 if(this.isConfigurationOpen()) {
142 if(this.isFullSize()) {
143 this.halfSizeWindow();
144 } else if(this.isHalfSize()) {
145 this.normalSizeWindow();
146 } else if (this.isNormalSize()){
147 this.halfSizeWindow();
149 this.normalSizeWindow();
152 if(this.isFullSize()) {
153 this.normalSizeWindow();
154 } else if(this.isHalfSize() || this.isNormalSize()) {
155 this.fullSizeWindow();
160 isNormalSize: function() {
161 return (this.window.getWidth() + 'px' == this.size.widthNormal && this.window.getHeight() + 'px' == this.size.heightNormal);
164 isHalfSize: function() {
165 return (this.window.getWidth() + 'px' == this.size.widthHalf && this.window.getHeight() + 'px' == this.size.heightHalf);
168 isFullSize: function() {
169 return (this.window.getWidth() + 'px' == this.size.widthFull && this.window.getHeight() + 'px' == this.size.heightFull);
172 normalSizeWindow: function() {
173 new Effect.Morph(this.window, {style : 'width: ' + this.size.widthNormal + '; height: ' + this.size.heightNormal + ';', duration : 0.4});
176 halfSizeWindow: function() {
177 new Effect.Morph(this.window, {style : 'width: ' + this.size.widthHalf + '; height: ' + this.size.heightHalf + ';', duration : 0.4});
180 fullSizeWindow: function() {
181 new Effect.Morph(this.window, {style : 'width: ' + this.size.widthFull + '; height: ' + this.size.heightFull + ';', duration : 0.4});
184 hideOtherWindows: function() {
185 $$('.slide-window-container').each(function(el, index) {
188 width : this.size.widthNormal,
189 height : this.size.heightNormal
194 setConfigurationObj: function(obj) {
195 this.configurationObj = obj;
198 setWindowElementsEvent: function(repeaterEl, gridEl, requestObj) {
199 this.repeaterEl = repeaterEl;
200 this.gridEl = gridEl;
201 this.loadRequest = requestObj;
202 this.markAllChecked(false);
203 this.setLoadRequest();
204 this.postWindowOpen();
207 setLoadRequest: function() {
210 dataList = $(this.gridEl).select('tr');
212 } else if ($(this.repeaterEl + '_Container')) {
213 dataList = $(this.repeaterEl + '_Container').select('div.slide-window-element');
216 dataList.each(function(tr) {
217 $(tr).observe('click', function(index, clickedEl) {
218 var target = clickedEl.target || clickedEl.srcElement;
219 var clicked = $(target.id);
220 // for element selection action (clicked checkbox) configuration window is not open
221 if(clicked && clicked.hasAttribute('type') && clicked.readAttribute('type') == 'checkbox') {
225 var el = $(tr).down('input[type=hidden]')
227 var val = el.getValue();
228 this.loadRequest.ActiveControl.CallbackParameter = val;
229 this.loadRequest.dispatch();
230 this.configurationObj.openConfigurationWindow(this);
236 isConfigurationOpen: function() {
238 $$(this.elements.configurationWindows, this.elements.configurationProgress).each(function(el) {
239 if(el.getStyle('display') == 'block') {
247 sortTable: function (col, reverse) {
248 var table = document.getElementById(this.gridEl);
249 var tb = table.tBodies[0], tr = Array.prototype.slice.call(tb.rows, 0), i;
250 reverse = -((+reverse) || -1);
251 tr = tr.sort(function (a, b) {
253 var val_a = a.cells[col].textContent.trim();
254 var val_b = b.cells[col].textContent.trim();
255 if (!isNaN(parseFloat(val_a)) && isFinite(val_a) && !isNaN(parseFloat(val_b)) && isFinite(val_b)) {
258 val = val_a.localeCompare(val_b);
260 return reverse * (val);
262 for(i = 0; i < tr.length; ++i) tb.appendChild(tr[i]);
265 makeSortable: function () {
267 var table = document.getElementById(this.gridEl);
268 table.tHead.style.cursor = 'pointer';
269 var th = table.tHead, i;
270 th && (th = th.rows[0]) && (th = th.cells);
276 while (--i >= 1) (function (i) {
278 th[i].addEventListener('click', function () {
279 self.sortTable(i, (dir = 1 - dir));
284 setSearch: function() {
285 var search_pattern = new RegExp(this.search.value)
286 $$('div[id="' + this.windowId + this.elements.containerSuffix + '"] div.' + this.elements.contentItems).each(function(value){
288 if(search_pattern.match(value.childNodes[2].textContent) == false) {
289 value.setStyle({'display' : 'none'});
291 value.setStyle({'display' : ''});
293 }.bind(search_pattern));
295 $$('div[id="' + this.windowId + this.elements.containerSuffix + '"] tr.' + this.elements.contentItems + ', div[id="' + this.windowId + this.elements.containerSuffix + '"] tr.' + this.elements.contentAlternatingItems).each(function(value){
296 if(search_pattern.match(value.down('div').innerHTML) == false) {
297 value.setStyle({'display' : 'none'});
299 value.setStyle({'display' : ''});
301 }.bind(search_pattern));
303 setElementsCount : function() {
304 var title_el = $(this.windowId + this.elements.titleSuffix);
305 var elements_count = $$('div[id="' + this.windowId + this.elements.containerSuffix + '"] div.' + this.elements.contentItems).length || $$('div[id="' + this.windowId + this.elements.containerSuffix + '"] tr.' + this.elements.contentItems + ', div[id="' + this.windowId + this.elements.containerSuffix + '"] tr.' + this.elements.contentAlternatingItems).length;
306 var count_el = $(this.windowId + this.elements.titleSuffix).getElementsByTagName('span')[0];
307 $(count_el).update(' (' + elements_count + ')');
309 toggleToolbar: function() {
310 if (this.isToolbarOpen() === false) {
311 this.markAllChecked(false);
313 Effect.toggle($(this.windowId + this.elements.toolbarSuffix), 'slide', { duration: 0.2});
315 isToolbarOpen: function() {
316 return $(this.windowId + this.elements.toolbarSuffix).visible();
318 setActions: function() {
319 var table = $(this.window).down('table');
320 var checkboxes = table.select('input[name="actions_checkbox"]');
321 checkboxes.each(function(el) {
322 el.observe('change', function() {
323 var is_checked = this.is_any_checked(checkboxes);
324 if(is_checked === true && !this.areActionsOpen()) {
326 } else if (is_checked === false && this.areActionsOpen()) {
332 is_any_checked: function(checkboxes) {
333 var is_checked = false;
334 checkboxes.each(function(ch) {
335 if(ch.checked == true) {
343 markAllChecked: function(check) {
345 var table = $(this.window).down('table');
346 var checkboxes = table.select('input[name="actions_checkbox"]');
348 if(checkboxes.length > 0) {
349 checkboxes.each(function(ch, index) {
350 if (ch.up('tr').visible()) {
351 containerId = ch.getAttribute('rel');
352 if (ch.checked == false && check == true) {
354 } else if (ch.checked == true && check == false) {
357 this.markChecked(containerId, ch.checked, ch.value);
360 this.packChecked(containerId);
369 markChecked: function(containerId, checked, param, pack) {
370 if (this.checked.length == 0) {
371 if(checked == true) {
372 this.checked.push(param);
375 index = this.checked.indexOf(param);
376 if(checked === true && index == -1) {
377 this.checked.push(param);
378 } else if (checked === false && index > -1) {
379 this.checked.splice(index, 1);
383 if(checked == true) {
385 } else if(this.checked.length == 0) {
390 this.packChecked(containerId);
393 packChecked: function(containerId) {
394 var values_packed = this.checked.join(';');
395 $(containerId).setValue(values_packed);
397 showActions: function() {
398 if (this.areActionsOpen()) {
401 if (this.isToolbarOpen()) {
402 this.toggleToolbar();
404 Effect.toggle($(this.windowId + this.elements.actionsSuffix), 'slide', { duration: 0.2});
406 hideActions: function() {
407 if (!this.areActionsOpen()) {
411 Effect.toggle($(this.windowId + this.elements.actionsSuffix), 'slide', { duration: 0.2});
413 areActionsOpen: function() {
414 return $(this.windowId + this.elements.actionsSuffix).visible();
416 postWindowOpen: function() {
418 this.setElementsCount();
422 var SlideWindow = new SlideWindowClass()
424 document.observe("dom:loaded", function() {
425 if(Prototype.Browser.IE || Prototype.Browser.Gecko) {
426 $$('input[type=checkbox], input[type=submit], input[type=radio], a').each(function(el) {
427 el.observe('focus', function() {