1 var SlideWindowClass = Class.create({
13 configurationObj: null,
25 heightNormal : '325px',
34 content: 'div.slide-window-content',
35 containerSuffix: '-slide-window-container',
36 containerProgressSuffix: '-slide-window-progress',
37 configurationWindows: 'div.configuration',
38 configurationProgress: 'div.configuration-progress',
39 contentItems: 'slide-window-element',
40 contentAlternatingItems: 'slide-window-element-alternating',
41 toolsButtonSuffix: '-slide-window-tools',
42 optionsButtonSuffix: '-slide-window-options',
43 actionsSuffix: '-slide-window-actions',
44 toolbarSuffix: '-slide-window-toolbar',
45 titleSuffix: '-slide-window-title',
46 actionsButton : 'actions_btn'
49 initialize: function(windowId, data) {
50 if(typeof(windowId) == "undefined") {
54 this.windowId = windowId;
55 this.window = $(this.windowId + this.elements.containerSuffix);
56 this.tools = $(this.windowId + this.elements.toolsButtonSuffix);
57 this.options = $(this.windowId + this.elements.optionsButtonSuffix);
58 this.titlebar = $(this.windowId + this.elements.titleSuffix);
60 if(data.hasOwnProperty('showId')) {
61 this.showEl = $(data.showId);
63 alert('slide-window.js - "showId" property does not exists.');
67 if(data.hasOwnProperty('hideId')) {
68 this.hideEl = $(data.hideId);
70 alert('slide-window.js - "hideId" property does not exists.');
74 if(data.hasOwnProperty('fullSizeId')) {
75 this.fullSizeEl = $(data.fullSizeId);
77 alert('slide-window.js - "fullSizeId" property does not exists.');
81 if(data.hasOwnProperty('search')) {
82 this.search = $(data.search);
84 alert('slide-window.js - "search" property does not exists.');
90 objectExists: function(key) {
91 return this.objects.hasOwnProperty(key);
94 registerObj: function(key, obj) {
95 if(this.objectExists(key) === false) {
96 this.objects[key] = obj;
100 getObj: function(key) {
102 if(this.objectExists(key) === true) {
103 obj = this.objects[key];
108 setEvents: function() {
109 this.showEl.observe('click', function(){
113 this.hideEl.observe('click', function(){
117 this.fullSizeEl.observe('click', function(){
121 this.titlebar.observe('dblclick', function() {
125 this.search.observe('keyup', function(){
129 this.tools.observe('click', function() {
130 this.toggleToolbar();
133 this.options.observe('click', function() {
134 this.toggleToolbar();
137 this.setActionsBtnEvents();
140 setActionsBtnEvents: function() {
141 var actions_btn_container = this.window.getElementsByClassName(this.elements.actionsButton);
142 if (actions_btn_container.length === 1) {
143 var actions_btn = actions_btn_container[0].getElementsByTagName('INPUT');
144 if (actions_btn.length === 1) {
145 actions_btn[0].addEventListener('mouseup', function(e) {
146 var row = this.getGridRowUnderCursor(e);
147 var el = $(row).down('input[type=hidden]');
149 var val = el.getValue();
150 this.actionsRequest.ActiveControl.CallbackParameter = val;
151 this.actionsRequest.dispatch();
158 openWindow : function() {
159 this.hideOtherWindows();
160 Effect.toggle(this.window, 'slide', { duration: 0.1, afterFinish : function() {
161 this.halfSizeWindow();
166 closeWindow : function() {
167 Effect.toggle(this.window, 'slide', { duration: 0.3, afterFinish : function() {
173 isWindowOpen: function() {
174 return !(this.window.style.display === 'none');
177 showProgress: function(show) {
178 var progress = $(this.windowId + this.elements.containerProgressSuffix);
180 progress.setStyle({display: 'block'});
181 } else if (show === false) {
186 resetSize : function() {
187 if(this.isConfigurationOpen()) {
188 if(this.isFullSize()) {
189 this.halfSizeWindow();
190 } else if(this.isHalfSize()) {
191 this.normalSizeWindow();
192 } else if (this.isNormalSize()){
193 this.halfSizeWindow();
195 this.normalSizeWindow();
198 if(this.isFullSize()) {
199 this.normalSizeWindow();
200 } else if(this.isHalfSize() || this.isNormalSize()) {
201 this.fullSizeWindow();
206 isNormalSize: function() {
207 return (this.windowSize == this.size.widthNormal && this.window.getHeight() + 'px' == this.size.heightNormal);
210 isHalfSize: function() {
211 return (this.windowSize == this.size.widthHalf && this.window.getHeight() + 'px' == this.size.heightHalf);
214 isFullSize: function() {
215 return (this.windowSize == this.size.widthFull && this.window.getHeight() + 'px' == this.size.heightFull);
218 normalSizeWindow: function() {
219 new Effect.Morph(this.window, {style : 'width: ' + this.size.widthNormal + '; height: ' + this.size.heightNormal + ';', duration : 0.4});
220 this.windowSize = this.size.widthNormal;
223 halfSizeWindow: function() {
224 new Effect.Morph(this.window, {style : 'width: ' + this.size.widthHalf + '; height: ' + this.size.heightHalf + ';', duration : 0.4});
225 this.windowSize = this.size.widthHalf;
228 fullSizeWindow: function() {
229 new Effect.Morph(this.window, {style : 'width: ' + this.size.widthFull + '; height: ' + this.size.heightFull + ';', duration : 0.4});
230 this.windowSize = this.size.widthFull;
233 hideOtherWindows: function() {
234 $$('.slide-window-container').each(function(el, index) {
237 width : this.size.widthNormal,
238 height : this.size.heightNormal
243 setConfigurationObj: function(obj) {
244 this.configurationObj = obj;
247 setWindowElementsEvent: function(opts) {
248 this.repeaterEl = opts.repeater_id + '_Container';
249 this.gridEl = opts.grid_id;
250 this.loadRequest = opts.request_obj;
251 if (opts.hasOwnProperty('actions_obj')) {
252 this.actionsRequest = opts.actions_obj;
255 if (this.initElementId) {
256 this.openConfigurationById(this.initElementId);
257 this.initElementId = null;
258 // for open window by init element, default set second tab
259 this.configurationObj.switchTabByNo(2);
262 this.showProgress(false);
263 this.markAllChecked(false);
264 this.setLoadRequest();
265 this.postWindowOpen();
268 setLoadRequest: function() {
270 var repeater = $(this.repeaterEl);
271 var grid = $(this.gridEl);
273 dataList = grid.select('tr');
275 } else if (repeater) {
276 dataList = repeater.select('div.slide-window-element');
279 var set_callback_parameter = function(element) {
280 var el = $(element).down('input[type=hidden]')
282 var val = el.getValue();
283 this.openConfigurationById(val);
287 dataList.each(function(tr) {
288 $(tr).observe('click', function(index, clickedEl) {
289 var target = clickedEl.target || clickedEl.srcElement;
290 var clicked = $(target.id);
291 // for element selection action (clicked checkbox) configuration window is not open
292 if(clicked && clicked.hasAttribute('type') && clicked.readAttribute('type') == 'checkbox') {
295 set_callback_parameter(tr);
298 Formatters.set_formatters();
299 this.revertSortingFromCookie();
302 openConfigurationById: function(id) {
303 this.loadRequest.ActiveControl.CallbackParameter = id;
304 this.loadRequest.dispatch();
305 this.configurationObj.openConfigurationWindow(this);
308 isConfigurationOpen: function() {
310 $$(this.elements.configurationWindows, this.elements.configurationProgress).each(function(el) {
311 if(el.getStyle('display') == 'block') {
319 sortTable: function (grid_id, col, reverse, set_cookie) {
320 var table = document.getElementById(grid_id);
321 var tb = table.tBodies[0], tr = Array.prototype.slice.call(tb.rows, 0), i;
322 reverse = -((+reverse) || -1);
323 tr = tr.sort(function (a, b) {
324 var val, val_a, val_b, el_a, el_b;
325 el_a = a.cells[col].childNodes[1];
326 el_b = b.cells[col].childNodes[1];
327 if (el_a && el_b && el_a.nodeType === 1 && el_b.nodeType === 1 && el_a.hasAttribute('rel') && el_b.hasAttribute('rel')) {
328 val_a = el_a.getAttribute('rel');
329 val_b = el_b.getAttribute('rel');
331 val_a = a.cells[col].textContent.trim();
332 val_b = b.cells[col].textContent.trim();
334 if (!isNaN(parseFloat(val_a)) && isFinite(val_a) && !isNaN(parseFloat(val_b)) && isFinite(val_b)) {
337 val = val_a.localeCompare(val_b);
339 return reverse * (val);
342 for (i = 0; i < tr.length; i++) {
343 even = ((i % 2) == 0);
345 tr[i].className = this.elements.contentItems;
347 tr[i].className = this.elements.contentAlternatingItems;
349 tb.appendChild(tr[i]);
351 if (set_cookie === true) {
352 Cookies.set_cookie(this.gridEl, col + ':' + reverse);
356 makeSortable: function (grid) {
358 var grid_id, set_cookie;
361 // for external grids (non-slide) do not remember sorting order
364 grid_id = this.gridEl;
367 var table = document.getElementById(grid_id);
368 table.tHead.style.cursor = 'pointer';
369 var th = table.tHead, i;
370 th && (th = th.rows[0]) && (th = th.cells);
377 // skip first column if in column header is input (checkbox for elements mark)
378 if (th[0].childNodes[0].nodeName == "INPUT") {
381 while (--i >= downCounter) (function (i) {
383 th[i].addEventListener('click', function () {
384 self.sortTable(grid_id, i, (dir = 1 - dir), set_cookie);
389 revertSortingFromCookie: function() {
390 var sorting = Cookies.get_cookie(this.gridEl);
391 if (sorting != null) {
392 var sort_param = sorting.split(':');
393 var col = parseInt(sort_param[0], 10);
394 var order = -(parseInt(sort_param[1], 10));
395 this.sortTable(this.gridEl, col, order);
399 setSearch: function() {
400 var search_pattern = new RegExp(this.search.value, 'i');
401 var repeater = $(this.repeaterEl);
402 var grid = $(this.gridEl);
404 repeater.select('div.' + this.elements.contentItems).each(function(value){
405 if(search_pattern.test(value.childNodes[2].textContent) == false) {
406 value.setStyle({'display' : 'none'});
408 value.setStyle({'display' : ''});
410 }.bind(search_pattern));
414 grid.select('tbody tr').each(function(value) {
415 var tds = value.select('td');
418 for (var i = 0; i < tds.length; i++) {
419 td = tds[i].textContent.trim();
420 if(search_pattern.test(td) == true) {
431 }.bind(search_pattern));
434 setElementsCount : function() {
435 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;
436 var count_el = $(this.windowId + this.elements.titleSuffix).getElementsByTagName('span')[0];
437 $(count_el).update(' (' + elements_count + ')');
439 toggleToolbar: function() {
440 if (this.isToolbarOpen() === false) {
441 this.markAllChecked(false);
443 Effect.toggle($(this.windowId + this.elements.toolbarSuffix), 'slide', { duration: 0.2});
445 isToolbarOpen: function() {
446 return $(this.windowId + this.elements.toolbarSuffix).visible();
448 setActions: function() {
449 var checkboxes = this.getCheckboxes();
450 checkboxes.each(function(el) {
451 el.observe('change', function() {
452 var is_checked = this.isAnyChecked(checkboxes);
453 if(is_checked === true && !this.areActionsOpen()) {
455 } else if (is_checked === false && this.areActionsOpen()) {
461 isAnyChecked: function(checkboxes) {
462 var is_checked = false;
463 checkboxes.each(function(ch) {
464 if(ch.checked == true) {
472 getCheckboxes: function() {
473 var grid = $(this.gridEl);
476 checkboxes = grid.select('input[name="actions_checkbox"]');
481 areCheckboxesChecked: function() {
482 var checkboxes = this.getCheckboxes();
483 return this.isAnyChecked(checkboxes);
486 markAllChecked: function(check) {
488 var checkboxes = this.getCheckboxes();
490 if(checkboxes.length > 0) {
491 checkboxes.each(function(ch, index) {
492 if (ch.up('tr').visible()) {
493 containerId = ch.getAttribute('rel');
494 if (ch.checked == false && check == true) {
496 } else if (ch.checked == true && check == false) {
499 this.markChecked(containerId, ch.checked, ch.value);
503 this.packChecked(containerId);
513 markChecked: function(containerId, checked, param, pack) {
514 if (this.checked.length == 0) {
515 if(checked == true) {
516 this.checked.push(param);
519 index = this.checked.indexOf(param);
520 if(checked === true && index == -1) {
521 this.checked.push(param);
522 } else if (checked === false && index > -1) {
523 this.checked.splice(index, 1);
527 if(checked == true) {
529 } else if(this.checked.length == 0) {
534 this.packChecked(containerId);
537 packChecked: function(containerId) {
538 var values_packed = this.checked.join(';');
539 $(containerId).setValue(values_packed);
541 showActions: function() {
542 if (this.areActionsOpen()) {
545 if (this.isToolbarOpen()) {
546 this.toggleToolbar();
548 Effect.toggle($(this.windowId + this.elements.actionsSuffix), 'slide', { duration: 0.2});
550 hideActions: function() {
551 if (!this.areActionsOpen()) {
555 Effect.toggle($(this.windowId + this.elements.actionsSuffix), 'slide', { duration: 0.2});
557 areActionsOpen: function() {
558 return $(this.windowId + this.elements.actionsSuffix).visible();
560 postWindowOpen: function() {
562 this.setElementsCount();
563 this.setOptionsBtn();
565 setOptionsBtn: function() {
566 var options_btn = this.window.getElementsByClassName(this.elements.actionsButton);
567 var table_window = $(this.windowId + this.elements.containerSuffix).down(this.elements.content);
568 if (options_btn.length === 1) {
569 options_btn = options_btn[0];
570 table_window.stopObserving('mouseover');
571 table_window.observe('mouseover', function(e) {
572 var el = this.getGridRowUnderCursor(e);
573 if (el && (el.className == this.elements.contentItems || el.className == this.elements.contentAlternatingItems)) {
574 el.style.backgroundColor = '#aeb2b6';
575 options_btn.setStyle({display: ''});
576 var scroll_y = document.viewport.getScrollOffsets().top;
577 var y = (el.viewportOffset().top + scroll_y - 57).toString() + 'px';
578 options_btn.setStyle({top: y});
580 options_btn.setStyle({display: 'none'});
583 table_window.stopObserving('mouseout');
584 table_window.observe('mouseout', function(e) {
585 table_window.select('TR').forEach(function(el) {
586 el.style.backgroundColor = '';
588 options_btn.setStyle({display: 'none'});
592 getGridRowUnderCursor: function(e) {
593 var x = e.clientX - 100;
595 var element_mouse_is_over = document.elementFromPoint(x, y);
597 var el_over = $(element_mouse_is_over);
598 if (el_over && el_over.nodeName != 'TR') {
599 el = el_over.down('tr');
601 el = el_over.up('tr');
606 setInitElementId: function(id) {
607 this.initElementId = id;
609 quickJumpToElement: function(id, btn_id, panel_obj) {
610 this.setInitElementId(id);
611 panel_obj.show('container');
612 if (this.isWindowOpen() === true) {
613 this.openConfigurationById(id);
620 var SlideWindow = new SlideWindowClass()
622 document.observe("dom:loaded", function() {
623 if(Prototype.Browser.IE || Prototype.Browser.Gecko || Prototype.Browser.WebKit) {
624 $$('input[type=checkbox], input[type=submit], input[type=radio], input[type=image], a').each(function(el) {
625 el.observe('focus', function() {
632 function setContentWidth() {
633 var content_width = $('container').getWidth() - $('menu-left').getWidth() - 1;
634 $('content').setStyle({'width': content_width + 'px'});
638 Event.observe(window, 'resize', function() {
642 document.observe("dom:loaded", function() {