Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / static / im / js / common.js @ 99ec73ba

History | View | Annotate | Download (13.8 kB)

1
function setContainerMinHeight(applicableDiv) {
2

    
3
    if ($(applicableDiv).length > 0) {
4
        //var h = $('.header').height(); div.header is not found 
5
        var f = $('.footer').height();
6
        var w = $(window).height();
7
        var pTop = parseInt (($(applicableDiv).css('padding-top').replace("px", "")) );
8
        var pBottom = parseInt (($(applicableDiv).css('padding-bottom').replace("px", "")));
9

    
10
        var c = w - ( f+pTop+pBottom+36);//36 is header's height.
11
        $(applicableDiv).css('min-height', c);
12
    }    
13

    
14
}
15

    
16
function tableFixedCols(table, firstColWidth ){
17
        ColsNum = $('table th').size();
18
        var ColWidth = parseFloat( (100 - firstColWidth)/ColsNum ).toFixed(0);
19
        var ColWidthPercentage = ColWidth+'%';
20
        var firstColWidthPercentage = firstColWidth+'%';
21
        $('table th, table td').attr('width',ColWidthPercentage ); 
22
        $('table tr td:first-child, table tr th:first-child').attr('width',firstColWidthPercentage );
23
        
24
}
25

    
26
function addClassHover(hoverEl, applicableEl){ 
27
        $(hoverEl).hover(
28
      function () {
29
               
30
         $(applicableEl).addClass('red-border')
31
      }, 
32
      function () {
33
              $(applicableEl).removeClass('red-border');
34
    
35
    });
36
}
37
//equal heights
38
 
39
(function($) {
40
        $.fn.equalHeights = function(minHeight, maxHeight) {
41
                tallest = (minHeight) ? minHeight : 0;
42
                this.each(function() {
43
                        if($(this).height() > tallest) {
44
                                tallest = $(this).height();
45
                        }
46
                });
47
                if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
48
                return this.each(function() {
49
                        $(this).height(tallest);
50
                });
51
        }
52
})(jQuery);
53

    
54

    
55

    
56
// fix for iPhone - iPad orientation bug 
57
var metas = document.getElementsByTagName('meta');
58
function resetViewport() {
59
    var i;
60
    if (navigator.userAgent.match(/iPhone/i)) {
61
                  for (i=0; i<metas.length; i++) {
62
                    if (metas[i].name == "viewport") {
63
                              metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
64
                    }
65
                  }
66
          }
67
}
68
resetViewport();
69
    
70
window.onorientationchange = function() {
71
    resetViewport();
72
};
73
    
74
function gestureStart() {
75
  for (i=0; i<metas.length; i++) {
76
    if (metas[i].name == "viewport") {
77
      metas[i].content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
78
    }
79
  }
80
}
81

    
82
if (navigator.userAgent.match(/iPhone/i)) {
83
        document.addEventListener("gesturestart", gestureStart, false);
84
}
85
//end of fix
86

    
87

    
88
/* project members page js */
89
function check_form_actions_inactive(){
90
  if ( $('#members-table tbody td.check input:checked').length >0 ) {
91
    $('.projects .form-actions').removeClass('inactive');
92
  } else {
93
    $('.projects .form-actions').addClass('inactive');
94
  }
95

    
96
  // updating form data
97
  var forms = $("form.link-like:has('input.members-batch-action')");
98
  forms.each(function(index, form){
99
    var member_ids, checked;
100
    form = $(form);
101
    form.find("input.member-option").remove();
102
    checked = $('#members-table tbody td.check input:checked');
103
    member_ids = _.map(checked, function(el) {
104
      return parseInt($(el).val());
105
    });
106

    
107
    _.each(member_ids, function(id) {
108
      var newel;
109
      newel = $("<input name='members' class='member-option' type='hidden' value='"+id+"'>");
110
      form.append(newel);
111
    });
112
  })
113
}
114

    
115

    
116
function tableSort(tableEl, iDisplayLength, bFilter) {
117

    
118
  // bFilter is an optional parameter
119
  // if bFilter is provided, search input will be visible
120
  bFilter = typeof bFilter !== 'undefined' ? bFilter : true;
121

    
122
  // iDisplayLength is an optional parameter
123
  // iDisplayLength controls the max number of rows visible to each page
124
  iDisplayLength = typeof iDisplayLength !== 'undefined' ? iDisplayLength : 10;
125

    
126
  // return if table holds no data
127
  if (tableEl.find('tbody').find('tr').length <2 ){
128
    return;
129
  }
130

    
131
  var dateArr = [];
132
  var numHTMLArr = [];
133

    
134
  _.each(tableEl.find('th'),function(value, key, list){
135
    if ( $(value).attr('class').indexOf("date")> -1 ) {
136
      dateArr.push(key);
137
    }
138
    if ( $(value).attr('class').indexOf("members_count")> -1) {
139
      numHTMLArr.push(key);
140
    };
141

    
142
  });
143

    
144
  // control pagination & table sorting for projects intro page
145
  tableEl
146
    .bind('page', function () {
147
      $('#members-table input').attr('checked', false);
148
      check_form_actions_inactive();
149
     })
150
    .dataTable({
151
    "bFilter": bFilter,
152
    "iDisplayLength": iDisplayLength,
153
    "bLengthChange": true,
154
    "sDom": '<"top">frt<"clearfix"><"bottom"i<"select"l>p>',
155
    "bStateSave": true,
156
    "aoColumnDefs": [
157
         { "sType": "num-html", "aTargets": numHTMLArr },
158
         { "sType": "date-uk", "aTargets": dateArr },
159
    ],
160
    "oLanguage": {
161
      "sLengthMenu": 'Pagination <select>'+
162
           '<option value="10">10</option>'+
163
           '<option value="25">25</option>'+
164
           '<option value="50">50</option>'+
165
           '<option value="-1">All</option>'+
166
           '</select>'
167
    },
168
  });
169

    
170
  $('.dataTables_wrapper').addClass('clearfix');
171
}
172

    
173
$(document).ready(function() {
174
        
175
    var is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
176

    
177
    /* api access */
178
    $(".token-view .detail").click(function() { 
179
      $(this).find("input").select();
180
    });
181
            
182
    $('#dummy_auth_token').html( $('.token-view input[name="auth_token"]').val());
183
    $('#dummy_token_url').html( $('.token-view input[name="token_url"]').val())
184

    
185

    
186
    if (is_firefox ){
187
      $('.dummy-input').css('display','block');
188
      $('.dummy-input').next('input').css('visibility','hidden');
189
    }
190

    
191
    /* api access test
192
    
193
    */
194

    
195
         
196
    setContainerMinHeight('.container .wrapper');
197
    //tableFixedCols('my-projects', 25);
198
        
199
    $('.show-extra').click(function(e) {
200
        e.preventDefault();
201
        $(this).parents('.bg-wrap').find('.extra').slideToggle(600);
202
    });
203
    $('.hide-extra').click(function(e) {
204
        e.preventDefault();
205
        $(this).parents('.bg-wrap').find('.extra').slideUp(600);
206
    });
207
    
208
    $('.box-more p').click(function(e) {
209
        $(this).siblings('.clearfix').toggle('slow');
210
        $(this).parents('.box-more').toggleClass('border');
211
    });
212
        
213
        var fixTopMessageHeight = function() {
214
                var topMargin = parseInt($('.mainlogo img').height())+parseInt($('.top-msg').css('marginBottom'));
215
                $('.mainlogo').css('marginTop','-'+topMargin+'px');
216
        }
217
        
218
        if ($('.mainlogo img').length > 0) {
219
                $('.mainlogo img').bind('load', fixTopMessageHeight)
220
        } else {
221
                fixTopMessageHeight();
222
        }
223
        
224
        $('.top-msg a.close').click(function(e) {
225
                e.preventDefault();
226
        $('.top-msg').animate({
227
            paddingTop:'0',
228
            paddingBottom:'0',
229
            height:'0'
230
        }, 1000, function (){
231
             $('.top-msg').removeClass('active')
232
        });
233
        $('.mainlogo').animate({
234
            marginTop:'0'
235
        }, 1000, function (){
236
             //todo
237
        });
238
    });        
239
    
240
     
241
        $('select.dropkicked').dropkick({
242
                change: function (value, label) {
243
                    $(this).parents('form').submit();
244
                    
245
                }
246
        });
247
        
248
        $('.with-info select').attr('tabindex','1');
249
    $('.with-info select').dropkick();
250
    
251
    $('.top-msg .success').parents('.top-msg').addClass('success');
252
    $('.top-msg .error').parents('.top-msg').addClass('error');
253
    $('.top-msg .warning').parents('.top-msg').addClass('warning');
254
    $('.top-msg .info').parents('.top-msg').addClass('info');
255
    
256
    // clouds homepage animation
257
    $('#animation a').hover(
258
      function () {
259
              
260
        $(this).animate({
261
           top: '+=-10'   
262
           }, 600, function() {
263
                   if ($(this).find('img').attr('src').indexOf("_top") == -1) {
264
                           var src = $(this).find('img').attr('src').replace('.png', '_top.png')
265
                        $(this).find('img').attr("src", src);
266
                   }
267

    
268
                });
269
        $(this).siblings('p').find('img').animate({
270
          width: '60%'       
271
        }, 600);
272
      }, 
273
      function () {
274

    
275
        $(this).animate({top: '0'}, 600, function() {
276
                var src = $(this).find('img').attr('src').replace('_top.png', '.png')
277
                       $(this).find('img').attr("src", src);
278
                });
279
        $(this).siblings('p').find('img').animate({
280
          width: '65%'       
281
        },600);
282
      }
283
    );
284
    
285
    
286
    
287
    
288
    $(function() {                 
289
                $( "#id_start_date" ).datepicker({
290
                        minDate: 0,
291
                        defaultDate: "+0", 
292
            dateFormat: "yy-mm-dd",
293
            onSelect: function( selectedDate ) {
294
                $( "#id_end_date" ).datepicker( "option", "minDate", selectedDate );
295
            }
296
        });
297
        
298
        $( "#id_end_date" ).datepicker({
299
                defaultDate: "+3w", 
300
            dateFormat: "yy-mm-dd",
301
            onSelect: function( selectedDate ) {
302
                $( "#id_start_date" ).datepicker( "option", "maxDate", selectedDate );
303
            }
304
        });
305
        });
306
        
307
         
308
        
309
        $('table .more-info').click(function(e){
310
                e.preventDefault();
311
                $(this).toggleClass('open');
312
                if ($(this).hasClass('open')){
313
                        $(this).html('- less info ')
314
                } else {
315
                        $(this).html('+ more info ')
316
                }
317
                $(this).parents('tr').next('tr').toggle();
318
                 
319
        });
320
        
321
        $('.projects .details .edit').click( function(e){
322
                e.preventDefault();
323
                $(this).parents('.details').children('.data').hide();
324
                $(this).parents('.details').children('.editable').slideDown(500, 'linear');
325
                $(this).hide();
326
        });
327
        
328
        $('.editable .form-row').each(function() {
329
                        if ( $(this).hasClass('with-errors') ){
330
                                $('.editable').show();
331
                                $('.projects .details a.edit, .projects .details .data').hide();
332
                                
333
                        }
334
                });
335
        
336

    
337

    
338

    
339
 
340
        $("input.leave, input.join").click(function (e) {
341
        e.preventDefault();
342
        var form = $(this).parents('form');
343
        var dialog = $(this).parents('.msg-wrap').find('.dialog');
344

    
345
                $('.dialog').hide();
346
    if ($(this).parents('.form-actions').hasClass('inactive')) {
347
      return false;
348
    }
349
                $(this).parents('.msg-wrap').find('.dialog').show();
350
        var offset = dialog.offset();
351

    
352
        if (offset.left <= 10) {
353
          dialog.css({'left': '10px'})
354
        }
355
        if (offset.top <= 10) {
356
          dialog.css({'top': '10px'})
357
        }
358

    
359
        if (dialog.find('textarea').length > 0) {
360
          dialog.find('textarea').val('');
361
          dialog.find('textarea').focus();
362
        }
363

    
364
                return false;      
365
                
366
    });
367
    
368
     $('.msg-wrap .no').click( function(e){
369
                    e.preventDefault();
370
                    $(this).parents('.dialog').hide();
371
        e.stopPropagation();
372
            })
373

    
374
      $(document).click(function() {
375
        $('.msg-wrap .dialog').hide();
376
      });
377

    
378
     
379
    $('.msg-wrap .yes').click( function(e){
380
                e.preventDefault();
381
        var dialog = $(this).parents('.msg-wrap').find('.dialog');
382
        var form = $(this).parents('.msg-wrap').find('form');
383
        var fields = dialog.find('input, textarea')
384
        
385
        var toremove = [];
386
        fields.each(function(){
387
          var f = $(this).clone();
388
          f.hide();
389
          form.append(f);
390
          f.val($(this).val());
391
          toremove.push(f);
392
        });
393
        
394
        form.submit();
395
        })
396
    
397
    $('.hidden-submit input[readonly!="True"]').focus(function () {
398
         $('.hidden-submit .form-row.submit').slideDown(500);
399
    });
400
      
401
    setTimeout(function() {
402
        var innerInputs = $('form.innerlabels input[type="text"], form.innerlabels input[type="password"]');
403
        _.each(innerInputs, function(val, key,list){
404
          if ($(val).val()){
405
            $(val).siblings('label').css('opacity','0');
406
          };
407
        });
408
    }, 200);
409

    
410
        
411
        // landing-page initialization
412
    if ($('.landing-page').length > 0) {
413
      var wrapper = $(".landing-page");
414
      var services = wrapper.find(".landing-service");
415
      services.hover(function(e) {
416
        var cls, service_cls, cloudbar_li, offset, positionX;
417
        cls = _.filter($(this).attr("class").split(" "), function(cls) {
418
          return cls.indexOf("service-") == 0
419
        });
420
        if (!cls.length) { return }
421
        service_cls = $.trim(cls[0]);
422
        extra = 0;
423
        if (service_cls == 'service-astakos') {
424
          cloudbar_li = $(".cloudbar .profile");
425
          extra = 50;
426
        } else {
427
          cloudbar_li = $(".cloudbar ul.services li." + service_cls);
428
          if (cloudbar_li.index() != 0) {
429
            extra = 20;
430
          }
431
        }
432
              offset = cloudbar_li.offset();
433
        if (!offset) { return }
434
              positionX = offset.left + extra;
435
              $('#hand').css('left',positionX + 'px');
436
        $('#hand').show();
437
      }, function (e) {
438
              $('#hand').hide();
439
      });
440
    }
441

    
442
    $('.pagination a.disabled').click(function(e){
443
            e.preventDefault();
444
    });
445
          
446
        // fix for recaptcha fields
447
        $('#okeanos_recaptcha').parents('.form-row').find('.extra-img').hide();          
448
   
449
   check_form_actions_inactive();  
450

    
451

    
452

    
453
$('#members-table td.email').click(function(e){
454
  var that = $(this).parent('tr').find('.check').find('input[type="checkbox"]')
455
  if(that.is(":checked")){
456
    that.removeAttr('checked');
457
  } else {
458
    that.attr('checked', 'checked');
459
  }
460
  check_form_actions_inactive();
461

    
462
})
463

    
464
$('#members-table tr th.check input').change(function(e){
465
  if($(this).is(":checked")){
466
    $('#members-table tbody td.check input').attr('checked', 'checked');
467
  } else {
468
    $('#members-table tbody td.check input').removeAttr('checked');
469
  } 
470
});
471

    
472
$('#members-table tr .check input').click(function(e){
473
  check_form_actions_inactive()
474
});
475

    
476
  $('.renew-token a.confirm').click(function(e){
477
    e.preventDefault();
478
    e.stopPropagation();
479
    renewToken();
480
  });
481

    
482
  $('.renew-token a.do').click(function(e){
483
    e.preventDefault();
484
    e.stopPropagation(); 
485
    var els = [$(".renew-token .sub"),$('.renew-token .confirm'), $('.renew-token .close')];
486
    _.each(els, function (el) { el.show();})
487
  })
488

    
489
  $('.renew-token a.close').click(function(e){
490
    e.preventDefault();
491
    e.stopPropagation();
492
    var els = [$(".renew-token .sub"),$('.renew-token .confirm'), $('.renew-token .close')];
493
    _.each(els, function (el) { el.hide();})
494
    $('.renew-token a.do').show();
495
  })
496

    
497
  tableSort($('.projects-intro').siblings('table#projects-list'), 10, true );
498
  tableSort($('.search-projects').siblings('table#projects-list'), 25, true);
499
  tableSort($('#members-table'), 3, true);
500

    
501

    
502
});
503

    
504
        
505
$(window).resize(function() {
506
    
507
   setContainerMinHeight('.container .wrapper');
508

    
509
});