1 var SlideWindowClass = Class.create({
13 configurationObj: null,
23 heightNormal : '325px',
32 containerSuffix : '-slide-window-container',
33 configurationWindows : 'div.configuration',
34 configurationProgress: 'div.configuration-progress',
35 contentItems : 'slide-window-element',
36 contentAlternatingItems : 'slide-window-element-alternating',
37 toolsButtonSuffix : '-slide-window-tools',
38 optionsButtonSuffix : '-slide-window-options',
39 actionsSuffix : '-slide-window-actions',
40 toolbarSuffix : '-slide-window-toolbar',
41 titleSuffix : '-slide-window-title'
44 initialize: function(windowId, data) {
45 if(typeof(windowId) == "undefined") {
49 this.windowId = windowId;
50 this.window = $(this.windowId + this.elements.containerSuffix);
51 this.tools = $(this.windowId + this.elements.toolsButtonSuffix);
52 this.options = $(this.windowId + this.elements.optionsButtonSuffix);
53 this.titlebar = $(this.windowId + this.elements.titleSuffix);
55 if(data.hasOwnProperty('showId')) {
56 this.showEl = $(data.showId);
58 alert('slide-window.js - "showId" property does not exists.');
62 if(data.hasOwnProperty('hideId')) {
63 this.hideEl = $(data.hideId);
65 alert('slide-window.js - "hideId" property does not exists.');
69 if(data.hasOwnProperty('fullSizeId')) {
70 this.fullSizeEl = $(data.fullSizeId);
72 alert('slide-window.js - "fullSizeId" property does not exists.');
76 if(data.hasOwnProperty('search')) {
77 this.search = $(data.search);
79 alert('slide-window.js - "search" property does not exists.');
85 objectExists: function(key) {
86 return this.objects.hasOwnProperty(key);
89 registerObj: function(key, obj) {
90 if(this.objectExists(key) === false) {
91 this.objects[key] = obj;
95 getObj: function(key) {
97 if(this.objectExists(key) === true) {
98 obj = this.objects[key];
103 setEvents: function() {
104 this.showEl.observe('click', function(){
108 this.hideEl.observe('click', function(){
112 this.fullSizeEl.observe('click', function(){
116 this.titlebar.observe('dblclick', function() {
120 this.search.observe('keyup', function(){
124 this.tools.observe('click', function() {
125 this.toggleToolbar();
128 this.options.observe('click', function() {
129 this.toggleToolbar();
133 openWindow : function() {
134 this.hideOtherWindows();
135 Effect.toggle(this.window, 'slide', { duration: 0.3, afterFinish : function() {
136 this.normalSizeWindow();
141 closeWindow : function() {
142 Effect.toggle(this.window, 'slide', { duration: 0.3, afterFinish : function() {
148 isWindowOpen: function() {
149 return !(this.window.style.display === 'none');
152 resetSize : function() {
153 if(this.isConfigurationOpen()) {
154 if(this.isFullSize()) {
155 this.halfSizeWindow();
156 } else if(this.isHalfSize()) {
157 this.normalSizeWindow();
158 } else if (this.isNormalSize()){
159 this.halfSizeWindow();
161 this.normalSizeWindow();
164 if(this.isFullSize()) {
165 this.normalSizeWindow();
166 } else if(this.isHalfSize() || this.isNormalSize()) {
167 this.fullSizeWindow();
172 isNormalSize: function() {
173 return (this.windowSize == this.size.widthNormal && this.window.getHeight() + 'px' == this.size.heightNormal);
176 isHalfSize: function() {
177 return (this.windowSize == this.size.widthHalf && this.window.getHeight() + 'px' == this.size.heightHalf);
180 isFullSize: function() {
181 return (this.windowSize == this.size.widthFull && this.window.getHeight() + 'px' == this.size.heightFull);
184 normalSizeWindow: function() {
185 new Effect.Morph(this.window, {style : 'width: ' + this.size.widthNormal + '; height: ' + this.size.heightNormal + ';', duration : 0.4});
186 this.windowSize = this.size.widthNormal;
189 halfSizeWindow: function() {
190 new Effect.Morph(this.window, {style : 'width: ' + this.size.widthHalf + '; height: ' + this.size.heightHalf + ';', duration : 0.4});
191 this.windowSize = this.size.widthHalf;
194 fullSizeWindow: function() {
195 new Effect.Morph(this.window, {style : 'width: ' + this.size.widthFull + '; height: ' + this.size.heightFull + ';', duration : 0.4});
196 this.windowSize = this.size.widthFull;
199 hideOtherWindows: function() {
200 $$('.slide-window-container').each(function(el, index) {
203 width : this.size.widthNormal,
204 height : this.size.heightNormal
209 setConfigurationObj: function(obj) {
210 this.configurationObj = obj;
213 setWindowElementsEvent: function(repeaterEl, gridEl, requestObj) {
214 this.repeaterEl = repeaterEl;
215 this.gridEl = gridEl;
216 this.loadRequest = requestObj;
217 this.markAllChecked(false);
218 this.setLoadRequest();
219 this.postWindowOpen();
222 setLoadRequest: function() {
225 dataList = $(this.gridEl).select('tr');
227 } else if ($(this.repeaterEl + '_Container')) {
228 dataList = $(this.repeaterEl + '_Container').select('div.slide-window-element');
231 dataList.each(function(tr) {
232 $(tr).observe('click', function(index, clickedEl) {
233 var target = clickedEl.target || clickedEl.srcElement;
234 var clicked = $(target.id);
235 // for element selection action (clicked checkbox) configuration window is not open
236 if(clicked && clicked.hasAttribute('type') && clicked.readAttribute('type') == 'checkbox') {
240 var el = $(tr).down('input[type=hidden]')
242 var val = el.getValue();
243 this.loadRequest.ActiveControl.CallbackParameter = val;
244 this.loadRequest.dispatch();
245 this.configurationObj.openConfigurationWindow(this);
251 isConfigurationOpen: function() {
253 $$(this.elements.configurationWindows, this.elements.configurationProgress).each(function(el) {
254 if(el.getStyle('display') == 'block') {
262 sortTable: function (col, reverse) {
263 var table = document.getElementById(this.gridEl);
264 var tb = table.tBodies[0], tr = Array.prototype.slice.call(tb.rows, 0), i;
265 reverse = -((+reverse) || -1);
266 tr = tr.sort(function (a, b) {
268 var val_a = a.cells[col].textContent.trim();
269 var val_b = b.cells[col].textContent.trim();
270 if (!isNaN(parseFloat(val_a)) && isFinite(val_a) && !isNaN(parseFloat(val_b)) && isFinite(val_b)) {
273 val = val_a.localeCompare(val_b);
275 return reverse * (val);
277 for(i = 0; i < tr.length; ++i) tb.appendChild(tr[i]);
280 makeSortable: function () {
282 var table = document.getElementById(this.gridEl);
283 table.tHead.style.cursor = 'pointer';
284 var th = table.tHead, i;
285 th && (th = th.rows[0]) && (th = th.cells);
292 // skip first column if in column header is input (checkbox for elements mark)
293 if (th[0].childNodes[0].nodeName == "INPUT") {
296 while (--i >= downCounter) (function (i) {
298 th[i].addEventListener('click', function () {
299 self.sortTable(i, (dir = 1 - dir));
304 setSearch: function() {
305 var search_pattern = new RegExp(this.search.value)
306 $$('div[id="' + this.windowId + this.elements.containerSuffix + '"] div.' + this.elements.contentItems).each(function(value){
308 if(search_pattern.match(value.childNodes[2].textContent) == false) {
309 value.setStyle({'display' : 'none'});
311 value.setStyle({'display' : ''});
313 }.bind(search_pattern));
315 $$('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){
316 if(search_pattern.match(value.down('div').innerHTML) == false) {
317 value.setStyle({'display' : 'none'});
319 value.setStyle({'display' : ''});
321 }.bind(search_pattern));
323 setElementsCount : function() {
324 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;
325 var count_el = $(this.windowId + this.elements.titleSuffix).getElementsByTagName('span')[0];
326 $(count_el).update(' (' + elements_count + ')');
328 toggleToolbar: function() {
329 if (this.isToolbarOpen() === false) {
330 this.markAllChecked(false);
332 Effect.toggle($(this.windowId + this.elements.toolbarSuffix), 'slide', { duration: 0.2});
334 isToolbarOpen: function() {
335 return $(this.windowId + this.elements.toolbarSuffix).visible();
337 setActions: function() {
338 var table = $(this.window).down('table');
339 var checkboxes = table.select('input[name="actions_checkbox"]');
340 checkboxes.each(function(el) {
341 el.observe('change', function() {
342 var is_checked = this.is_any_checked(checkboxes);
343 if(is_checked === true && !this.areActionsOpen()) {
345 } else if (is_checked === false && this.areActionsOpen()) {
351 is_any_checked: function(checkboxes) {
352 var is_checked = false;
353 checkboxes.each(function(ch) {
354 if(ch.checked == true) {
362 markAllChecked: function(check) {
364 var table = $(this.window).down('table');
365 var checkboxes = table.select('input[name="actions_checkbox"]');
367 if(checkboxes.length > 0) {
368 checkboxes.each(function(ch, index) {
369 if (ch.up('tr').visible()) {
370 containerId = ch.getAttribute('rel');
371 if (ch.checked == false && check == true) {
373 } else if (ch.checked == true && check == false) {
376 this.markChecked(containerId, ch.checked, ch.value);
380 this.packChecked(containerId);
390 markChecked: function(containerId, checked, param, pack) {
391 if (this.checked.length == 0) {
392 if(checked == true) {
393 this.checked.push(param);
396 index = this.checked.indexOf(param);
397 if(checked === true && index == -1) {
398 this.checked.push(param);
399 } else if (checked === false && index > -1) {
400 this.checked.splice(index, 1);
404 if(checked == true) {
406 } else if(this.checked.length == 0) {
411 this.packChecked(containerId);
414 packChecked: function(containerId) {
415 var values_packed = this.checked.join(';');
416 $(containerId).setValue(values_packed);
418 showActions: function() {
419 if (this.areActionsOpen()) {
422 if (this.isToolbarOpen()) {
423 this.toggleToolbar();
425 Effect.toggle($(this.windowId + this.elements.actionsSuffix), 'slide', { duration: 0.2});
427 hideActions: function() {
428 if (!this.areActionsOpen()) {
432 Effect.toggle($(this.windowId + this.elements.actionsSuffix), 'slide', { duration: 0.2});
434 areActionsOpen: function() {
435 return $(this.windowId + this.elements.actionsSuffix).visible();
437 postWindowOpen: function() {
439 this.setElementsCount();
443 var SlideWindow = new SlideWindowClass()
445 document.observe("dom:loaded", function() {
446 if(Prototype.Browser.IE || Prototype.Browser.Gecko || Prototype.Browser.WebKit) {
447 $$('input[type=checkbox], input[type=submit], input[type=radio], a').each(function(el) {
448 el.observe('focus', function() {
455 function setContentWidth() {
456 var content_width = $('container').getWidth() - $('menu-left').getWidth() - 1;
457 $('content').setStyle({'width': content_width + 'px'});
461 Event.observe(window, 'resize', function() {
465 document.observe("dom:loaded", function() {