1 var SlideWindowClass = jQuery.klass({
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.');
88 this.halfSizeWindow();
91 objectExists: function(key) {
92 return this.objects.hasOwnProperty(key);
95 registerObj: function(key, obj) {
96 if(this.objectExists(key) === false) {
97 this.objects[key] = obj;
101 getObj: function(key) {
103 if(this.objectExists(key) === true) {
104 obj = this.objects[key];
109 setEvents: function() {
110 this.showEl.on('click', function(){
114 this.hideEl.on('click', function(){
118 this.fullSizeEl.on('click', function(){
122 this.titlebar.on('dblclick', function() {
126 this.search.on('keyup', function(){
130 this.tools.on('click', function() {
131 this.toggleToolbar();
134 this.options.on('click', function() {
135 this.toggleToolbar();
138 this.setActionsBtnEvents();
141 setActionsBtnEvents: function() {
143 var actions_btn_container = this.window[0].getElementsByClassName(this.elements.actionsButton);
144 if (actions_btn_container.length === 1) {
145 var actions_btn = actions_btn_container[0].getElementsByTagName('INPUT');
146 if (actions_btn.length === 1) {
147 actions_btn[0].addEventListener('mouseup', function(e) {
148 var row = self.getGridRowUnderCursor(e);
149 var el = $(row).find('div[data-type="item_value"]');
150 if(el.length === 1) {
151 self.actionsRequest.setCallbackParameter(el[0].getAttribute('rel'));
152 self.actionsRequest.dispatch();
159 openWindow : function() {
160 this.hideOtherWindows();
161 this.window.slideToggle({duration: 100, done: function() {
162 this.halfSizeWindow();
167 closeWindow : function() {
168 this.window.slideToggle({done: function() {
174 isWindowOpen: function() {
175 return !(this.window[0].style.display === 'none');
178 showProgress: function(show) {
179 var progress = $('#' + this.windowId + this.elements.containerProgressSuffix);
181 progress.css({display: 'block'});
182 } else if (show === false) {
187 resetSize : function() {
188 if(this.isConfigurationOpen()) {
189 if(this.isFullSize()) {
190 this.halfSizeWindow();
191 } else if(this.isHalfSize()) {
192 this.normalSizeWindow();
193 } else if (this.isNormalSize()){
194 this.halfSizeWindow();
196 this.normalSizeWindow();
199 if(this.isFullSize()) {
200 this.normalSizeWindow();
201 } else if(this.isHalfSize() || this.isNormalSize()) {
202 this.fullSizeWindow();
207 isNormalSize: function() {
208 return (this.windowSize == this.size.widthNormal && this.window.height() + 'px' == this.size.heightNormal);
211 isHalfSize: function() {
212 return (this.windowSize == this.size.widthHalf && this.window.height() + 'px' == this.size.heightHalf);
215 isFullSize: function() {
216 return (this.windowSize == this.size.widthFull && this.window.height() + 'px' == this.size.heightFull);
219 normalSizeWindow: function() {
220 this.window.animate({width: this.size.widthNormal, height: this.size.heightNormal}, {duration : 400});
221 this.windowSize = this.size.widthNormal;
224 halfSizeWindow: function() {
225 this.window.animate({width: this.size.widthHalf, height: this.size.heightHalf}, {duration : 400});
226 this.windowSize = this.size.widthHalf;
229 fullSizeWindow: function() {
230 this.window.animate({width: this.size.widthFull, height: this.size.heightFull}, {duration : 400});
231 this.windowSize = this.size.widthFull;
234 hideOtherWindows: function() {
235 $('.slide-window-container').css({
237 width : this.size.widthNormal,
238 height : this.size.heightNormal
242 setConfigurationObj: function(obj) {
243 this.configurationObj = obj;
246 setWindowElementsEvent: function(opts) {
247 this.repeaterEl = opts.repeater_id + '_Container';
248 this.gridEl = opts.grid_id;
249 this.loadRequest = opts.request_obj;
250 if (opts.hasOwnProperty('actions_obj')) {
251 this.actionsRequest = opts.actions_obj;
254 if (this.initElementId) {
255 this.openConfigurationById(this.initElementId);
256 this.initElementId = null;
257 // for open window by init element, default set second tab
258 this.configurationObj.switchTabByNo(2);
261 this.showProgress(false);
262 this.markAllChecked(false);
263 this.setLoadRequest();
264 this.postWindowOpen();
267 setLoadRequest: function() {
269 var repeater = $('#' + this.repeaterEl);
270 var grid = $('#' + this.gridEl);
271 if(grid.length === 1) {
272 dataList = grid.find('tr');
274 } else if (repeater) {
275 dataList = repeater.find('div.slide-window-element');
278 var set_callback_parameter = function(element) {
280 if ($('#' + this.gridEl).length === 1) {
281 var el = $(element).find('div[data-type="item_value"]')
282 if (el.length === 1) {
283 val = el[0].getAttribute('rel');
285 } else if ($('#' + this.repeaterEl).length === 1) {
286 val = element.getAttribute('rel');
289 this.openConfigurationById(val);
293 dataList.each(function(index, tr) {
294 $(tr).on('click', function(event) {
295 var target = event.target || event.srcElement;
296 var clicked = document.getElementById(target.id);
297 // for element selection action (clicked checkbox) configuration window is not open
298 if(clicked && clicked.hasAttribute('type') && clicked.getAttribute('type') == 'checkbox') {
301 set_callback_parameter(tr);
304 Formatters.set_formatters();
305 if (grid.length === 1) {
306 this.revertSortingFromCookie();
310 openConfigurationById: function(id) {
311 this.loadRequest.setCallbackParameter(id);
312 this.loadRequest.dispatch();
313 this.configurationObj.openConfigurationWindow(this);
316 isConfigurationOpen: function() {
318 $(this.elements.configurationWindows + ', '+ this.elements.configurationProgress).each(function(index, el) {
319 if($(el).css('display') == 'block') {
327 sortTable: function (grid_id, col, reverse, set_cookie) {
328 var table = document.getElementById(grid_id);
329 var tb = table.tBodies[0], tr = Array.prototype.slice.call(tb.rows, 0), i;
330 reverse = -((+reverse) || -1);
331 tr = tr.sort(function (a, b) {
332 var val, val_a, val_b, el_a, el_b;
333 el_a = a.cells[col].childNodes[1];
334 el_b = b.cells[col].childNodes[1];
335 if (el_a && el_b && el_a.nodeType === 1 && el_b.nodeType === 1 && el_a.hasAttribute('rel') && el_b.hasAttribute('rel')) {
336 val_a = el_a.getAttribute('rel');
337 val_b = el_b.getAttribute('rel');
339 val_a = a.cells[col].textContent.trim();
340 val_b = b.cells[col].textContent.trim();
342 if (!isNaN(parseFloat(val_a)) && isFinite(val_a) && !isNaN(parseFloat(val_b)) && isFinite(val_b)) {
345 val = val_a.localeCompare(val_b);
347 return reverse * (val);
350 for (i = 0; i < tr.length; i++) {
351 even = ((i % 2) == 0);
353 tr[i].className = this.elements.contentItems;
355 tr[i].className = this.elements.contentAlternatingItems;
357 tb.appendChild(tr[i]);
359 if (set_cookie === true) {
360 Cookies.set_cookie(this.gridEl, col + ':' + reverse);
364 makeSortable: function (grid) {
366 var grid_id, set_cookie;
369 // for external grids (non-slide) do not remember sorting order
372 grid_id = this.gridEl;
375 var table = document.getElementById(grid_id);
376 table.tHead.style.cursor = 'pointer';
377 var th = table.tHead, i;
378 th && (th = th.rows[0]) && (th = th.cells);
385 // skip first column if in column header is input (checkbox for elements mark)
386 if (th[0].childNodes[0].nodeName == "INPUT") {
389 while (--i >= downCounter) (function (i) {
391 th[i].addEventListener('click', function () {
392 self.sortTable(grid_id, i, (dir = 1 - dir), set_cookie);
397 revertSortingFromCookie: function() {
398 var sorting = Cookies.get_cookie(this.gridEl);
399 if (sorting != null) {
400 var sort_param = sorting.split(':');
401 var col = parseInt(sort_param[0], 10);
402 var order = -(parseInt(sort_param[1], 10));
403 this.sortTable(this.gridEl, col, order);
407 setSearch: function() {
408 var search_pattern = new RegExp(this.search[0].value, 'i');
409 var repeater = $('#' + this.repeaterEl);
410 var grid = $('#' + this.gridEl);
411 if (repeater.length === 1) {
412 repeater.find('div.' + this.elements.contentItems).each(function(index, value){
414 if(search_pattern.test(value.childNodes[2].textContent) == false) {
415 $(value).css({'display' : 'none'});
417 $(value).css({'display' : ''});
419 }.bind(search_pattern));
422 if (grid.length === 1) {
423 grid.find('tbody tr').each(function(index, value) {
424 var tds = $(value).find('td');
427 for (var i = 0; i < tds.length; i++) {
428 td = tds[i].textContent.trim();
429 if(search_pattern.test(td) == true) {
440 }.bind(search_pattern));
443 setElementsCount : function() {
444 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;
445 var count_el = document.getElementById(this.windowId + this.elements.titleSuffix).getElementsByTagName('span')[0];
446 count_el.textContent = ' (' + elements_count + ')';
448 toggleToolbar: function() {
449 if (this.isToolbarOpen() === false) {
450 this.markAllChecked(false);
452 $('#' + this.windowId + this.elements.toolbarSuffix).slideToggle({duration: 200});
454 isToolbarOpen: function() {
455 return $('#' + this.windowId + this.elements.toolbarSuffix).is(':visible');
457 setActions: function() {
458 var checkboxes = this.getCheckboxes();
459 $(checkboxes).each(function(index, el) {
460 $(el).on('change', function() {
461 var is_checked = this.isAnyChecked(checkboxes);
462 if(is_checked === true && !this.areActionsOpen()) {
464 } else if (is_checked === false && this.areActionsOpen()) {
470 isAnyChecked: function(checkboxes) {
471 var is_checked = false;
472 $(checkboxes).each(function(index, ch) {
473 if(ch.checked == true) {
481 getCheckboxes: function() {
482 var grid = $('#' + this.gridEl);
484 if (grid.length === 1) {
485 checkboxes = grid.find('input[name="actions_checkbox"]');
490 areCheckboxesChecked: function() {
491 var checkboxes = this.getCheckboxes();
492 return this.isAnyChecked(checkboxes);
495 markAllChecked: function(check) {
497 var checkboxes = this.getCheckboxes();
499 if(checkboxes.length > 0) {
500 checkboxes.each(function(index, ch) {
501 if ($(ch).parents('tr').is(':visible')) {
502 containerId = ch.getAttribute('rel');
503 if (ch.checked == false && check == true) {
505 } else if (ch.checked == true && check == false) {
508 this.markChecked(containerId, ch.checked, ch.value);
512 this.packChecked(containerId);
522 markChecked: function(containerId, checked, param, pack) {
523 if (this.checked.length == 0) {
524 if(checked == true) {
525 this.checked.push(param);
528 index = this.checked.indexOf(param);
529 if(checked === true && index == -1) {
530 this.checked.push(param);
531 } else if (checked === false && index > -1) {
532 this.checked.splice(index, 1);
536 if(checked == true) {
538 } else if(this.checked.length == 0) {
543 this.packChecked(containerId);
546 packChecked: function(containerId) {
547 var values_packed = this.checked.join(';');
548 document.getElementById(containerId).value = values_packed;
550 showActions: function() {
551 if (this.areActionsOpen()) {
554 if (this.isToolbarOpen()) {
555 this.toggleToolbar();
557 $('#' + this.windowId + this.elements.actionsSuffix).slideDown({duration: 200});
559 hideActions: function() {
560 if (!this.areActionsOpen()) {
564 $('#' + this.windowId + this.elements.actionsSuffix).slideUp({duration: 200});
566 areActionsOpen: function() {
567 return $('#' + this.windowId + this.elements.actionsSuffix).is(':visible');
569 postWindowOpen: function() {
571 this.setElementsCount();
572 this.setOptionsBtn();
574 setOptionsBtn: function() {
575 var options_btn = this.window[0].getElementsByClassName(this.elements.actionsButton);
576 var table_window = $('#' + this.windowId + this.elements.containerSuffix).children(this.elements.content);
577 if (options_btn.length === 1) {
579 options_btn = options_btn[0];
580 table_window.off('mouseover');
581 table_window.on('mouseover', function(e) {
582 var el = self.getGridRowUnderCursor(e);
583 if (el.length === 1 && (el[0].className == self.elements.contentItems || el[0].className == self.elements.contentAlternatingItems)) {
584 el[0].style.backgroundColor = '#aeb2b6';
585 options_btn.style.display = '';
586 var scroll_y = $(document).scrollTop();
587 var y = ($(el).offset().top + scroll_y - 57).toString() + 'px';
588 options_btn.style.top = y;
590 options_btn.style.display = 'none';
593 table_window.off('mouseout');
594 table_window.on('mouseout', function(e) {
595 table_window.find('tr').each(function(index, el) {
596 el.style.backgroundColor = '';
598 options_btn.style.display = 'none';
602 getGridRowUnderCursor: function(e) {
603 var x = e.clientX - 100;
605 var element_mouse_is_over = document.elementFromPoint(x, y);
607 var el_over = $(element_mouse_is_over);
608 if (el_over.length === 1 && el_over[0].nodeName != 'TR') {
609 el = el_over.children('tr');
610 if (el.length === 0) {
611 el = el_over.parents('tr');
616 setInitElementId: function(id) {
617 this.initElementId = id;
619 quickJumpToElement: function(id, btn_id, panel_obj) {
620 this.setInitElementId(id);
621 panel_obj.show('container');
622 if (this.isWindowOpen() === true) {
623 this.openConfigurationById(id);
625 $('#' + btn_id).click();
630 var SlideWindow = new SlideWindowClass()
633 if(navigator.userAgent.search("MSIE") > -1 || navigator.userAgent.search("Firefox") > -1 || navigator.userAgent.search("Chrome") > -1) {
634 $('input[type=checkbox], input[type=submit], input[type=radio], input[type=image], a').each(function(el) {
635 $(el).on('focus', function() {
642 function setContentWidth() {
643 var content_width = $('#container').width() - $('#workspace-menu-left').width() - 1;
644 $('#content').css({'width': content_width + 'px'});
648 $(window).resize(function() {