-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.js
1211 lines (849 loc) · 33.5 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
*
* Nagios TV Monitor
* by Christopher P Carey - Dec 09 2010
* Last Modified - Feb 20 2013
*
* Update for EmberJS 1.0.0 RC
*
* main.js
*
******************************************************************************/
/*******************************************************************************
* Document Ready
******************************************************************************/
function ember_setup() {
// Create the Ember Application
window.App = Ember.Application.create();
// Create App.Item template
App.Item = Em.Object.extend();
// Use this for logging
App.log = function(msg){
if (window.console) console.info(msg);
};
// Set up Ember Routing
/*
App.Router.map(function() {
this.route("about", { path: "/about" });
this.route("detail", { path: "/detail" });
});
App.IndexRoute = Ember.Route.extend({
setupController: function(controller) {
// Set the IndexController's `title`
controller.set('title', "My App");
}
});
*/
}
function ember_setup_controllers() {
App.ApplicationController = Ember.ArrayController.extend({
name: 'NagiosTV',
current: [],
acked: [],
history: [],
refreshCurrent: 30,
refreshAcked: 31,
refreshNotification: 16,
maxCountNotification: 30,
timerCurrent: null,
timerAcked: null,
timerHistory: null,
versionMismatch: false,
version: '6',
versionString:'0.6',
versionServer: '',
versionStringServer: '',
remoteTime: '',
remoteTimeObject: 0,
remoteTimeZone: config_timezone || 'US/Pacific',
timeZoneDiffHours: 0,
currentDisconnected: true,
lastIdNotification: 0,
versionCheck: function() {
var that=this;
if (!config_version_check) {
App.log('versionCheck() Disabled');
return;
}
App.log('versionCheck() Starting');
$.ajax({
type: "POST",
url: "api.php",
data: "func=versioncheck&client_version="+that.get('versionCurrent'),
dataType: "json",
timeout: 5000,
error: function(data1, data2) {
App.log('versionCheck() Error getting version');
cancelTimers();
},
success: function(data){
App.log('VersionCheck success, ');
//App.log(data);
var jsondata = eval('(' + data + ')');
//App.log(jsondata);
if (jsondata.OK == 0) {
App.log('versionCheck() Error VersionCheck');
}
that.set('versionServer', jsondata.version);
that.set('versionStringServer', jsondata.version_string);
if (jsondata.version > that.get('version')) {
that.set('versionMismatch', true);
App.log('versionCheck() out of date. Client has '+that.get('version')+' and latest version is '+jsondata.version);
} else {
App.log('versionCheck() up to date. Client has '+that.get('version')+' and latest version is '+jsondata.version);
}
}
});
},
localTimeZone: function() {
// Auto Detect with http://www.pageloom.com/automatic-timezone-detection-with-javascript
var timezone = jstz.determine();
App.log('Detecting Local TimeZone as '+timezone.name());
return timezone.name();
}.property(),
startCountdown: function(obj) {
var that = this;
var count = that.get('refreshCurrent') - 1;
var origcount = that.get('refreshCurrent');
clearInterval(obj.countdown);
obj.set('timerPercent','100');
obj.countdown = setInterval(function(){
var pct = ((count-1) / origcount)*100;
obj.set('timerPercent',pct);
if (count == 0) {
clearInterval(obj.countdown);
}
count--;
}, 1000);
},
updateCurrent: function() {
var that = this;
$('#current-spinner').show();
$.ajax({
type: "GET",
url: "api.php",
data: "func=current",
dataType: "json",
timeout: 5000,
error: function(data1, data2) {
that.set('currentDisconnected', true);
var jsondata = eval('(' + data1.responseText + ')');
if (jsondata.OK == 0) {
App.log('updateCurrent() JSON Error');
$('#disconnected').html(jsondata.ERROR);
}
cancelTimers();
},
success: function(data){
that.set('currentDisconnected', false);
$('#current-spinner').fadeOut('slow');
if (data) {
var metadata = data[0];
var resultdata = data[1]["result"];
if (!resultdata) {
return;
}
if (metadata["stamp"] && metadata["offset"]) {
// set Local Time
var localdate = new timezoneJS.Date(new Date().toString(), that.get('localTimeZone'));
var local_offset = -localdate.getTimezoneOffset() / 60;
// set Remote Time
var remotetime = new Date(0);
remotetime.setUTCSeconds(metadata["stamp"]);
remotetime = new timezoneJS.Date(remotetime.toString(), that.get('remoteTimeZone'));
that.set('remoteTimeObject', remotetime);
that.set('remoteTime', remotetime.toString());
// difference time
var diff = remotetime.getHours() - localdate.getHours();
that.set('timeZoneDiffHours', diff);
// calculate difference hours with datejs TimeSpan
var span = localdate.getTimezoneOffset() - remotetime.getTimezoneOffset();
that.set('timeZoneDiffHours', span/60);
}
// grab the current list of items
var current = that.get('current');
// create an ember array if one does not exist
if (typeof(current) === "undefined") current = Ember.MutableArray();
// set the found bit on each item to 0. we will check for this bit later
// to compare the existing list of items against the one the server sends down
for(var j=0;j<current.length;j++) {
current[j].set('found', 0);
}
// aliases to keep inner loop fast
var cachedRes, newRes, found;
// We can't just blindly replace all the data. Thats sloppy as hell yo
// loop through the returned data and take a look at what we've got
for(var i=0;i<resultdata.length;i++) {
// search for a existing record
found = false;
newRes = resultdata[i];
for(var j=0;j<current.length;j++) {
cachedRes = current[j];
if (cachedRes.servicestatus_id === newRes.servicestatus_id) {
cachedRes.set('state_type', newRes.state_type);
cachedRes.set('current_state', newRes.current_state);
cachedRes.set('next_check', newRes.next_check);
cachedRes.set('output', newRes.output);
cachedRes.set('found', 1);
found = true;
}
}
if (!found) {
// item was returned and it was not found. lets add it into the array of items
//App.log('updateCurrent() new item');
//App.log(resultdata[i]);
// add this new item into the current array
current.pushObject( App.Item.create(newRes) );
}
}
// If the server returns nothing, lets clear the items out all at once.
// Fixes the delayed All services are UP bug
if (resultdata.length === 0) {
$('.currentitem').slideUp('slow', function(){
current.forEach(function(e) {
//console.info('foreach clearInterval '+e);
//console.info('foreach clearInterval '+e.softcountdown);
if (e && e.softcountdown) clearInterval(e.softcountdown);
});
current.clear();
});
}
// erase any items which were not returned
if (resultdata.length > 0 && typeof(current) !== "undefined") {
for(var j=current.length-1;j>=0;j--) {
//App.log('updateCurrent() Searching for found=0. current length is '+current.length+'. index '+j+' - found:'+current[j].get('found'));
if (current[j].get('found') === 0) {
//App.log('updateCurrent() Erasing index '+j+ ' current length is '+current.length);
_removeAndAnimate(j);
} else {
//App.log('updateCurrent() Item found at index '+j+'. Nothing to erase from current.');
}
}
}
// set the new current array back into the controller
that.set('current', current);
// Kick off the countdown again (which runs the bar chart and/or any other animations)
that.startCountdown(App.mainView);
}
// private helper function
function _removeAndAnimate(idx) {
$('#current-'+current[idx].servicestatus_id).slideUp('slow', function(){
if (current[idx] && current[idx].softcountdown) clearInterval(current[idx].softcountdown);
//App.log('updateCurrent() before removeAt():');
//App.log(current);
current.removeAt(idx);
});
}
} // end success
});
},
updateAcked: function() {
var that = this;
//TODO: fix ACKed. Its broken right now.
$('#acked-spinner').show();
// request the page
$.ajax({
type: "GET",
url: "api.php",
data: "func=acked",
dataType: "json",
success: function(data){
//App.log('updateAcked() success');
//App.log(data);
//that.set('currentDisconnected', false);
$('#acked-spinner').fadeOut('slow');
if (data) {
var metadata = data[0];
var resultdata = data[1]["result"];
//App.log('updateAcked() resultdata.length is '+resultdata.length);
if (!resultdata) {
return;
}
// grab the current list of items
var acked = that.get('acked');
//App.log('updateAcked() acked.length is '+acked.length);
// create an ember array if one does not exist
if (typeof(acked) === "undefined") acked = Ember.MutableArray();
// set the found bit on each item to 0. we will check for this bit later
// to compare the existing list of items against the one the server sends down
for(var j=0;j<acked.length;j++) {
//App.log('updateAcked() setting found to 0 on item '+j);
acked[j].set('found', 0);
}
// aliases to keep inner loop fast
var cachedRes, newRes, found;
// We can't just blindly replace all the data. Thats sloppy as hell yo
// loop through the returned data and take a look at what we've got
for(var i=0;i<resultdata.length;i++) {
// search for a existing record
found = false;
newRes = resultdata[i];
for(var j=0;j<acked.length;j++) {
cachedRes = acked[j];
if (cachedRes.servicestatus_id === newRes.servicestatus_id) {
cachedRes.set('state_type', newRes.state_type);
cachedRes.set('current_state', newRes.current_state);
cachedRes.set('next_check', newRes.next_check);
cachedRes.set('output', newRes.output);
cachedRes.set('found', 1);
found = true;
}
}
if (!found) {
// item was returned and it was not found. lets add it into the array of items
//App.log('updateAcked() new item');
//App.log(resultdata[i]);
// add this new item into the current array
acked.pushObject( App.Item.create(newRes) );
}
}
// If the server returns nothing, lets clear the items out all at once.
// Fixes the delayed All services are UP bug
if (resultdata.length === 0) {
$('.ackeditem').slideUp('slow', function(){
acked.forEach(function(e) {
console.info('foreach clearInterval '+e);
console.info('foreach clearInterval '+e.softcountdown);
if (e && e.softcountdown) clearInterval(e.softcountdown);
});
acked.clear();
});
}
// erase any items which were not returned
if (resultdata.length > 0 && typeof(acked) !== "undefined") {
for(var j=acked.length-1;j>=0;j--) {
//App.log('updateAcked() Searching for found=0. acked length is '+acked.length+'. index '+j+' - found:'+acked[j].get('found'));
if (acked[j].get('found') === 0) {
//App.log('updateAcked() Erasing index '+j+ ' acked length is '+acked.length);
_removeAndAnimate(j);
} else {
//App.log('updateAcked() Item found at index '+j+'. Nothing to erase from acked.');
}
}
}
// set the new current array back into the controller
that.set('acked', acked);
// Kick off the countdown again (which runs the bar chart and/or any other animations)
//that.startCountdown(App.mainView);
}
// private helper function
function _removeAndAnimate(idx) {
$('#acked-'+acked[idx].servicestatus_id).slideUp('slow', function(){
if (acked[idx] && acked[idx].softcountdown) clearInterval(acked[idx].softcountdown);
//App.log('updateCurrent() before removeAt():');
//App.log(current);
acked.removeAt(idx);
});
}
}
});
},
updateHistory: function() {
var that = this;
$('#notifications-spinner').show();
$.ajax({
type: "GET",
url: "api.php",
data: "func=history&maxcount="+App.applicationController.get('maxCountNotification')+"&lastid="+that.lastIdNotification,
dataType: "json",
success: function(data){
$('#notifications-spinner').fadeOut('slow');
if (data) {
var metadata = data[0];
var resultdata = data[1]["result"];
if (resultdata.length > 0) that.lastIdNotification = resultdata[0].notification_id;
// Loop through all returned data and write to screen
if (resultdata.length != 0) {
var oldhistoryarray = that.get('history');
// create an ember array if one does not exist
if (typeof(oldhistoryarray) === "undefined") oldhistoryarray = Ember.A();
oldhistoryarray.reverse();
var temphistoryarray = Ember.A();
for (var i=resultdata.length-1; i>=0; i--) {
// only add this item if it does not already exist on the page
if ($('#notification-'+resultdata[i].notification_id).length == 0) {
//give us the minutes since the previous history element
// subtract start_time from current time
var date1;
var date2 = new Date(Date.parse(resultdata[i].start_time));
if (oldhistoryarray.length > 0) {
//date1 = new Date(oldhistoryarray[oldhistoryarray.length-1].start_time);
date1 = new Date(Date.parse(oldhistoryarray[oldhistoryarray.length-1].start_time));
App.log('updateHistory() oldhistoryarray got date '+date1);
} else if(temphistoryarray.length > 0) {
//var datestring = Date.parse(temphistoryarray[temphistoryarray.length-1].start_time);
//date1 = new Date(temphistoryarray[temphistoryarray.length-1].start_time);
date1 = new Date(Date.parse(temphistoryarray[temphistoryarray.length-1].start_time));
//App.log('date1');
//App.log(temphistoryarray[temphistoryarray.length-1].start_time);
//App.log(date1);
//App.log('updateHistory() temphistory got date '+date1);
} else {
// FIXME: last one on the page falls into this
App.log('updateHistory() noarrays');
date1 = new Date();
}
var diff = date2.getTime() - date1.getTime();
resultdata[i].since_raw = diff;
diff = diff/(60*1000);
diff = diff.toFixed(0);
// set it
resultdata[i].since = diff;
// give us the minutes since the previous history element
temphistoryarray.pushObject(App.Item.create(resultdata[i]));
}
}
var newhistoryarray = oldhistoryarray.concat(temphistoryarray);
//var newhistoryarray = temphistoryarray.concat(oldhistoryarray);
newhistoryarray.reverse();
for(var j=0;j<newhistoryarray.length;j++) {
newhistoryarray[j].set('first', false);
}
//if (typeof(newhistoryarray) !== "undefined" && newhistoryarray.length > 0) {
newhistoryarray[0].set('first', true);
//}
// erase any history more than the g_maxCountNotification
//
//
for(var j=that.get('maxCountNotification');j<newhistoryarray.length;j++) {
console.info("Erasing extra history item "+j+".");
newhistoryarray.removeAt(j);
}
that.set('history', newhistoryarray); // need to appendChild
}
}
// update history even if no new data
that.updateHistoryAgo();
}
});
},
// For each history item, update ago, seconds_ago, and minutes_ago values
updateHistoryAgo: function() {
var that = this;
var history = that.get('history');
var date2 = new Date(); //now
var diffhours = that.get('timeZoneDiffHours');
// for each item in the history, update the 'ago' value
for (var h=history.length-1; h>=0; h--) {
// subtract start_time from current time
var date1 = new Date(Date.parse(history[h].start_time));
//date1.addHours(-diffhours);
var diff = date2.getTime() - date1.getTime();
var diff = date2 - date1;
var seconds = (diff/1000).toFixed(0);
var minutes = (diff/(60*1000)).toFixed(0);
diff = diff/(60*1000);
diff = diff.toFixed(0);
history[h].set('ago', diff);
history[h].set('seconds_ago', seconds);
history[h].set('minutes_ago', minutes);
}
}
});
App.applicationController = App.ApplicationController.create();
App.MainView = Ember.View.extend({
templateName: 'main-view',
totalGateways: -1,
currentDisconnected: function() {
//App.log('currentDisconnected() '+App.applicationController.current.length);
return App.applicationController.currentDisconnected;
}.property("App.applicationController.currentDisconnected"),
didInsertElement: function() {
//App.log('mainView didInsertElement');
//App.log(this.$());
},
currentEmpty: function() {
App.log('currentEmpty() '+App.applicationController.current.length);
if (App.applicationController.current.length > 0) {
return false;
} else {
return true;
}
}.property("App.applicationController.current.length"),
ackedEmpty: function() {
App.log('ackedEmpty() '+App.applicationController.get('acked').length);
if (App.applicationController.get('acked').length > 0) {
return false;
} else {
return true;
}
}.property("App.applicationController.acked.length"),
timerPercent:100,
timerWidth: function() {
return "width:"+this.timerPercent+"%";
}.property("timerPercent"),
didInsertElement: function() {
this.set('name', 'Nagios');
if (config_servername) {
//this.set('name', config_servername);
App.applicationController.set('name', config_servername);
}
if (config_icon) {
$('#config_icon').attr('src', config_icon);
}
/*
$('#remoteTimeDiv').click(function(){
$('#clockinfo').slideToggle();
});
*/
/*
$('#remoteTimeDiv').hover(
function(){
//in
//console.info('here');
$('#clockinfo').slideDown();
},
function(){
//out
$('#clockinfo').slideUp();
});
*/
}
});
App.mainView = App.MainView.create();
App.mainView.appendTo('#col1');
App.BarCurrent = Ember.View.extend({
templateName: 'bar-chart',
timerPercent:100,
timerWidth: function() {
return "width:"+App.mainView.get('timerPercent')+"%";
//return "width:50%";
}.property("App.mainView.timerPercent"),
bgColor: function() {
var found_crit = false;
var found_warn = false;
var current = App.applicationController.get('current');
// find out if there are any criticals
for(var j=0;j<current.length;j++) {
App.log(current[j].get('current_state'));
if (current[j].get('current_state') == 2) found_crit = true;
}
// find out if there are any warnings
for(var j=0;j<current.length;j++) {
if (current[j].get('current_state') == 1) found_warn = true;
}
if (found_crit) {
return "bgred";
} else if (found_warn) {
return "bgyellow";
} else {
return "bggreen";
//return "bggray";
}
}.property("App.applicationController.current.length"),
howManySeconds: function() {
return "width:"+App.applicationController.get('refreshCurrent');
}.property("App.applicationController.refreshCurrent")
});
App.barCurrent = App.BarCurrent.create();
//App.barCurrent.appendTo('#barAreaCurrent');
App.currentOkView = Ember.View.extend({
tagName: 'div',
classNames: ['displayNone'],
templateName: 'current-ok',
didInsertElement: function() {
this.$().slideDown('slow');
}
});
App.currentDisconnectedView = Ember.View.extend({
tagName: 'div',
classNames: ['displayNone'],
templateName: 'current-disconnected',
didInsertElement: function() {
this.$().slideDown('slow');
}
});
App.ackedOkView = Ember.View.extend({
tagName: 'div',
//classNames: ['displayNone'],
templateName: 'acked-ok',
didInsertElement: function() {
this.$().slideDown('slow');
}
});
App.historyItemView = Ember.View.extend({
tagName: 'div',
classNames: ['displayNone'],
templateName: 'history-item',
stringAgo: function() {
var content = this._context;
if (typeof(content) == "undefined") {
return false;
}
var seconds = content.seconds_ago;
var numdays = Math.floor(seconds / 86400);
var numhours = Math.floor((seconds % 86400) / 3600);
var numminutes = Math.floor(((seconds % 86400) % 3600) / 60);
var numseconds = ((seconds % 86400) % 3600) % 60;
return numdays + " days " + numhours + " hours " + numminutes + " minutes " + numseconds + " seconds";
}.property("this._context.ago"),
firstTimespan: function() {
var content = this._context;
if (typeof(content) == "undefined") {
return false;
}
if (content.first) {
return true;
} else {
return false;
}
}.property("this._context.first"),
largeTimespan: function() {
var content = this._context;
if (typeof(content) == "undefined") {
return false;
}
if (content.since > 30) {
return true;
} else {
return false;
}
}.property("this._context.since"),
stateClass: function() {
var content = this._context;
if (typeof(content) == "undefined") {
App.log('currentItemView() stateClass() this._context undefined ');
return false;
}
var state = content.state;
//App.log('currentItemView() stateClass() current_state '+state);
if (state === "1") {
return "state1";
} else if(state === "2") {
return "state2";
} else {
return "state";
}
}.property('this._context.state'),
didInsertElement: function() {
this.$().slideDown('slow');
}
});
App.currentItemView = Ember.View.extend({
tagName: 'div',
classNames: ['displayNone'],
templateName: 'current-item',
softtimerPercent:100,
softtimerWidth: function() {
return "width:"+this.softtimerPercent+"%";
}.property("softtimerPercent"),
bgColor: function() {
//return "bggreen";
return "bgyellow";
//return "bgred";
}.property(),
startsoftCountdown: function() {
var that=this;
var count = 60 - 1;
var origcount = 60;
clearInterval(that.softcountdown);
that.set('softtimerPercent','100');
that.softcountdown = setInterval(function(){
var pct = ((count-1) / origcount)*100;
that.set('softtimerPercent',pct);
if (count == 0) {
clearInterval(that.softcountdown);
}
count--;
}, 1000);
},
click: function() {
App.log('currentItemView() click()');
this.$().find('.eventDetail').slideToggle();
},
currentStateClass: function() {
var content = this._context;
if (typeof(content) == "undefined") {
App.log('currentItemView() currentStateClass() this._context undefined ');
return false;
}
var current_state = content.current_state;
App.log('currentItemView() currentStateClass() current_state '+current_state);
if (current_state === "1") {
return "state1";
} else if(current_state === "2") {
return "state2";
} else {
return "state";
}
}.property('this._context.current_state'),
stateTypeName: function() {
//console.dir(this);
var content = this._context;
if (typeof(content) == "undefined") {
return false;
}
App.log('currentItemView() stateTypeName state_type '+content.state_type);
if (content.state_type === "0") {
// TODO: fix and re-enable this
//this.startsoftCountdown();
return "SOFT";
} else if(content.state_type === "1") {
return "HARD";
} else {
return "UNKNOWN";
}
}.property('this._context.state_type'),
isSoft: function() {
var content = this._context;
if (typeof(content) == "undefined") {
return false;
}
App.log('currentItemView() isSoft state_type '+content.state_type);
if (content.state_type === "0") {
return true;
} else if(content.state_type === "1") {
return false;
} else {
return false;
}
}.property('this._context.state_type'),
downFor: function() {
var content = this._context;
if (typeof(content) == "undefined") {
return false;
}
var that = this;
var diffhours = App.applicationController.get('timeZoneDiffHours');
var date1 = new Date(Date.parse(content.last_state_change));
date1.addHours(-diffhours);
var remotedate = App.applicationController.get("remoteTimeObject");
var diff = remotedate - date1;
var seconds = (diff/1000).toFixed(0);
//seconds = seconds + (diffhours*3600);