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('input[type=hidden]');
150 if(el.length === 1) {
151 self.actionsRequest.setCallbackParameter(el[0].value);
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) {
279 var el = $(element).find('input[type=hidden]')
280 if(el.length === 1) {
281 var val = el[0].value;
282 this.openConfigurationById(val);
286 dataList.each(function(index, tr) {
287 $(tr).on('click', function(event) {
288 var target = event.target || event.srcElement;
289 var clicked = document.getElementById(target.id);
290 // for element selection action (clicked checkbox) configuration window is not open
291 if(clicked && clicked.hasAttribute('type') && clicked.getAttribute('type') == 'checkbox') {
294 set_callback_parameter(tr);
297 Formatters.set_formatters();
298 this.revertSortingFromCookie();
301 openConfigurationById: function(id) {
302 this.loadRequest.setCallbackParameter(id);
303 this.loadRequest.dispatch();
304 this.configurationObj.openConfigurationWindow(this);
307 isConfigurationOpen: function() {
309 $(this.elements.configurationWindows + ', '+ this.elements.configurationProgress).each(function(index, el) {
310 if($(el).css('display') == 'block') {
318 sortTable: function (grid_id, col, reverse, set_cookie) {
319 var table = document.getElementById(grid_id);
320 var tb = table.tBodies[0], tr = Array.prototype.slice.call(tb.rows, 0), i;
321 reverse = -((+reverse) || -1);
322 tr = tr.sort(function (a, b) {
323 var val, val_a, val_b, el_a, el_b;
324 el_a = a.cells[col].childNodes[1];
325 el_b = b.cells[col].childNodes[1];
326 if (el_a && el_b && el_a.nodeType === 1 && el_b.nodeType === 1 && el_a.hasAttribute('rel') && el_b.hasAttribute('rel')) {
327 val_a = el_a.getAttribute('rel');
328 val_b = el_b.getAttribute('rel');
330 val_a = a.cells[col].textContent.trim();
331 val_b = b.cells[col].textContent.trim();
333 if (!isNaN(parseFloat(val_a)) && isFinite(val_a) && !isNaN(parseFloat(val_b)) && isFinite(val_b)) {
336 val = val_a.localeCompare(val_b);
338 return reverse * (val);
341 for (i = 0; i < tr.length; i++) {
342 even = ((i % 2) == 0);
344 tr[i].className = this.elements.contentItems;
346 tr[i].className = this.elements.contentAlternatingItems;
348 tb.appendChild(tr[i]);
350 if (set_cookie === true) {
351 Cookies.set_cookie(this.gridEl, col + ':' + reverse);
355 makeSortable: function (grid) {
357 var grid_id, set_cookie;
360 // for external grids (non-slide) do not remember sorting order
363 grid_id = this.gridEl;
366 var table = document.getElementById(grid_id);
367 table.tHead.style.cursor = 'pointer';
368 var th = table.tHead, i;
369 th && (th = th.rows[0]) && (th = th.cells);
376 // skip first column if in column header is input (checkbox for elements mark)
377 if (th[0].childNodes[0].nodeName == "INPUT") {
380 while (--i >= downCounter) (function (i) {
382 th[i].addEventListener('click', function () {
383 self.sortTable(grid_id, i, (dir = 1 - dir), set_cookie);
388 revertSortingFromCookie: function() {
389 var sorting = Cookies.get_cookie(this.gridEl);
390 if (sorting != null) {
391 var sort_param = sorting.split(':');
392 var col = parseInt(sort_param[0], 10);
393 var order = -(parseInt(sort_param[1], 10));
394 this.sortTable(this.gridEl, col, order);
398 setSearch: function() {
399 var search_pattern = new RegExp(this.search[0].value, 'i');
400 var repeater = $('#' + this.repeaterEl);
401 var grid = $('#' + this.gridEl);
402 if (repeater.length === 1) {
403 repeater.find('div.' + this.elements.contentItems).each(function(index, value){
405 if(search_pattern.test(value.childNodes[2].textContent) == false) {
406 $(value).css({'display' : 'none'});
408 $(value).css({'display' : ''});
410 }.bind(search_pattern));
413 if (grid.length === 1) {
414 grid.find('tbody tr').each(function(index, value) {
415 var tds = $(value).find('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 = document.getElementById(this.windowId + this.elements.titleSuffix).getElementsByTagName('span')[0];
437 count_el.textContent = ' (' + elements_count + ')';
439 toggleToolbar: function() {
440 if (this.isToolbarOpen() === false) {
441 this.markAllChecked(false);
443 $('#' + this.windowId + this.elements.toolbarSuffix).slideToggle({duration: 200});
445 isToolbarOpen: function() {
446 return $('#' + this.windowId + this.elements.toolbarSuffix).is(':visible');
448 setActions: function() {
449 var checkboxes = this.getCheckboxes();
450 checkboxes.each(function(index, el) {
451 $(el).on('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(index, ch) {
464 if(ch.checked == true) {
472 getCheckboxes: function() {
473 var grid = $('#' + this.gridEl);
475 if (grid.length === 1) {
476 checkboxes = grid.find('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(index, ch) {
492 if ($(ch).parents('tr').is(':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 document.getElementById(containerId).value = values_packed;
541 showActions: function() {
542 if (this.areActionsOpen()) {
545 if (this.isToolbarOpen()) {
546 this.toggleToolbar();
548 $('#' + this.windowId + this.elements.actionsSuffix).slideDown({duration: 200});
550 hideActions: function() {
551 if (!this.areActionsOpen()) {
555 $('#' + this.windowId + this.elements.actionsSuffix).slideUp({duration: 200});
557 areActionsOpen: function() {
558 return $('#' + this.windowId + this.elements.actionsSuffix).is(':visible');
560 postWindowOpen: function() {
562 this.setElementsCount();
563 this.setOptionsBtn();
565 setOptionsBtn: function() {
566 var options_btn = this.window[0].getElementsByClassName(this.elements.actionsButton);
567 var table_window = $('#' + this.windowId + this.elements.containerSuffix).children(this.elements.content);
568 if (options_btn.length === 1) {
570 options_btn = options_btn[0];
571 table_window.off('mouseover');
572 table_window.on('mouseover', function(e) {
573 var el = self.getGridRowUnderCursor(e);
574 if (el.length === 1 && (el[0].className == self.elements.contentItems || el[0].className == self.elements.contentAlternatingItems)) {
575 el[0].style.backgroundColor = '#aeb2b6';
576 options_btn.style.display = '';
577 var scroll_y = $(document).scrollTop();
578 var y = ($(el).offset().top + scroll_y - 57).toString() + 'px';
579 options_btn.style.top = y;
581 options_btn.style.display = 'none';
584 table_window.off('mouseout');
585 table_window.on('mouseout', function(e) {
586 table_window.find('tr').each(function(index, el) {
587 el.style.backgroundColor = '';
589 options_btn.style.display = 'none';
593 getGridRowUnderCursor: function(e) {
594 var x = e.clientX - 100;
596 var element_mouse_is_over = document.elementFromPoint(x, y);
598 var el_over = $(element_mouse_is_over);
599 if (el_over.length === 1 && el_over[0].nodeName != 'TR') {
600 el = el_over.children('tr');
601 if (el.length === 0) {
602 el = el_over.parents('tr');
607 setInitElementId: function(id) {
608 this.initElementId = id;
610 quickJumpToElement: function(id, btn_id, panel_obj) {
611 this.setInitElementId(id);
612 panel_obj.show('container');
613 if (this.isWindowOpen() === true) {
614 this.openConfigurationById(id);
616 $('#' + btn_id).click();
621 var SlideWindow = new SlideWindowClass()
624 if(navigator.userAgent.search("MSIE") > -1 || navigator.userAgent.search("Firefox") > -1 || navigator.userAgent.search("Chrome") > -1) {
625 $('input[type=checkbox], input[type=submit], input[type=radio], input[type=image], a').each(function(el) {
626 $(el).on('focus', function() {
633 function setContentWidth() {
634 var content_width = $('#container').width() - $('#workspace-menu-left').width() - 1;
635 $('#content').css({'width': content_width + 'px'});
639 $(window).resize(function() {