Skip to content

Commit 1199ce5

Browse files
author
gaeljw
committed
Refactor temperatures step 2a : move tophtm in plain Angular
1 parent 6333ac5 commit 1199ce5

File tree

2 files changed

+72
-104
lines changed

2 files changed

+72
-104
lines changed

www/app/TemperatureController.js

Lines changed: 46 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
define(['app'], function (app) {
2-
app.controller('TemperatureController', [ '$scope', '$rootScope', '$location', '$http', '$interval', 'permissions', function($scope,$rootScope,$location,$http,$interval,permissions) {
2+
app.controller('TemperatureController', [ '$scope', '$rootScope', '$location', '$http', '$interval', '$window', 'permissions', function($scope,$rootScope,$location,$http,$interval,$window,permissions) {
33

44
var ctrl = this;
55

@@ -436,6 +436,7 @@ define(['app'], function (app) {
436436
$('#tempcontent').html(GetBackbuttonHTMLTable('ShowTemps')+htmlcontent);
437437
$('#tempcontent').i18n();
438438
$('#tempwidgets').hide();
439+
$('#temptophtm').hide();
439440

440441
$.content="#tempcontent";
441442

@@ -626,93 +627,14 @@ define(['app'], function (app) {
626627
}
627628
$('#modal').show();
628629

629-
var bShowRoomplan=false;
630-
$.RoomPlans = [];
631-
$.ajax({
632-
url: "json.htm?type=plans",
633-
async: false,
634-
dataType: 'json',
635-
success: function(data) {
636-
if (typeof data.result != 'undefined') {
637-
var totalItems=data.result.length;
638-
if (totalItems>0) {
639-
bShowRoomplan=true;
640-
// if (window.myglobals.ismobile==true) {
641-
// bShowRoomplan=false;
642-
// }
643-
if (bShowRoomplan==true) {
644-
$.each(data.result, function(i,item) {
645-
$.RoomPlans.push({
646-
idx: item.idx,
647-
name: item.Name
648-
});
649-
});
650-
}
651-
}
652-
}
653-
}
654-
});
655-
656-
var bHaveAddedDevider = false;
657-
var tophtm="";
658-
if ($.RoomPlans.length==0) {
659-
tophtm+=
660-
'\t<table class="bannav" id="bannav" border="0" cellpadding="0" cellspacing="0" width="100%">\n' +
661-
'\t<tr>\n' +
662-
'\t <td align="left" valign="top" id="timesun"></td>\n' +
663-
'\t <td align="right">\n';
664-
if (window.myglobals.ismobile==false) {
665-
tophtm+=
666-
'\t<table class="bannav" border="0" cellpadding="0" cellspacing="0" width="100%">\n' +
667-
'\t<tr>\n' +
668-
'\t <td align="left"></td>\n' +
669-
'\t <td align="right">\n' +
670-
'\t <a class="btnstyle" onclick="ShowCustomTempLog();" data-i18n="Custom Graph">Custom Graph</a>\n';
671-
if ($scope.config.Latitude!="") {
672-
tophtm+=
673-
'\t <a id="Forecast" class="btnstyle" onclick="ShowForecast();" data-i18n="Forecast">Forecast</a>\n';
674-
}
675-
tophtm+=
676-
'\t </td>\n' +
677-
'\t</tr>\n' +
678-
'\t</table>\n';
679-
}
680-
tophtm+=
681-
'</td>'+
682-
'\t</tr>\n' +
683-
'\t</table>\n';
684-
}
685-
else {
686-
tophtm+=
687-
'\t<table border="0" cellpadding="0" cellspacing="0" width="100%">\n' +
688-
'\t<tr>\n' +
689-
'\t <td align="left" valign="top" id="timesun"></td>\n' +
690-
'<td align="right" valign="top">'+
691-
'<span data-i18n="Room">Room</span>:&nbsp;<select id="comboroom" style="width:160px" class="combobox ui-corner-all">'+
692-
'<option value="0" data-i18n="All">All</option>'+
693-
'</select>'+
694-
'</td>'+
695-
'\t</tr>\n' +
696-
'\t</table>\n';
697-
if (window.myglobals.ismobile==false) {
698-
tophtm+=
699-
'\t<table class="bannav" border="0" cellpadding="0" cellspacing="0" width="100%">\n' +
700-
'\t<tr>\n' +
701-
'\t <td align="left"></td>\n' +
702-
'\t <td align="right">\n' +
703-
'\t <a class="btnstyle" onclick="ShowCustomTempLog();" data-i18n="Custom Graph">Custom Graph</a>\n';
704-
if ($scope.config.Latitude!="") {
705-
tophtm+=
706-
'\t <a id="Forecast" class="btnstyle" onclick="ShowForecast();" data-i18n="Forecast">Forecast</a>\n';
707-
}
708-
tophtm+=
709-
'\t </td>\n' +
710-
'\t</tr>\n' +
711-
'\t</table>\n';
712-
}
713-
}
630+
// TODO should belong to a global controller
631+
ctrl.isNotMobile = function() {
632+
return $window.myglobals.ismobile == false;
633+
};
634+
635+
var bHaveAddedDevider = false; // TODO remove ?
714636

715-
var i=0;
637+
var i=0; // TODO remove ?
716638

717639
$.ajax({
718640
url: "json.htm?type=devices&filter=temp&used=true&order=Name&plan="+window.myglobals.LastPlanSelected,
@@ -731,25 +653,12 @@ define(['app'], function (app) {
731653
}
732654
});
733655
$('#modal').hide();
734-
$('#tempcontent').html(tophtm);
656+
$('#temptophtm').show();
657+
$('#temptophtm').i18n();
735658
$('#tempwidgets').show();
736659
$('#tempwidgets').i18n();
660+
$('#tempcontent').html("");
737661
$('#tempcontent').i18n();
738-
if (bShowRoomplan==true) {
739-
$.each($.RoomPlans, function(i,item){
740-
var option = $('<option />');
741-
option.attr('value', item.idx).text(item.name);
742-
$("#tempcontent #comboroom").append(option);
743-
});
744-
if (typeof window.myglobals.LastPlanSelected!= 'undefined') {
745-
$("#tempcontent #comboroom").val(window.myglobals.LastPlanSelected);
746-
}
747-
$("#tempcontent #comboroom").change(function() {
748-
var idx = $("#tempcontent #comboroom option:selected").val();
749-
window.myglobals.LastPlanSelected=idx;
750-
ShowTemps();
751-
});
752-
}
753662

754663
$rootScope.RefreshTimeAndSun();
755664

@@ -1061,7 +970,37 @@ define(['app'], function (app) {
1061970
$interval.cancel($scope.mytimer);
1062971
$scope.mytimer = undefined;
1063972
}
1064-
});
973+
});
974+
975+
ctrl.RoomPlans = [{idx:0, name:$.t("All")}];
976+
$.ajax({
977+
url: "json.htm?type=plans",
978+
async: false,
979+
dataType: 'json',
980+
success: function(data) {
981+
if (typeof data.result != 'undefined') {
982+
var totalItems=data.result.length;
983+
if (totalItems>0) {
984+
$.each(data.result, function(i,item) {
985+
ctrl.RoomPlans.push({
986+
idx: item.idx,
987+
name: item.Name
988+
});
989+
});
990+
}
991+
}
992+
}
993+
});
994+
995+
if (typeof window.myglobals.LastPlanSelected!= 'undefined') {
996+
ctrl.roomSelected = window.myglobals.LastPlanSelected;
997+
}
998+
ctrl.changeRoom = function() {
999+
var idx = ctrl.roomSelected;
1000+
window.myglobals.LastPlanSelected = idx;
1001+
ShowTemps();
1002+
};
1003+
10651004
} ])
10661005
.directive('dztemperaturewidget', function() {
10671006
return {
@@ -1201,6 +1140,7 @@ define(['app'], function (app) {
12011140

12021141
ctrl.ShowTempLog = function(divId, fn) {
12031142
$('#tempwidgets').hide(); // TODO delete when multiple views implemented
1143+
$('#temptophtm').hide();
12041144
return ShowTempLog(divId, fn, ctrl.item.idx, escape(ctrl.item.Name));
12051145
};
12061146

@@ -1214,11 +1154,13 @@ define(['app'], function (app) {
12141154

12151155
ctrl.ShowNotifications = function(divId, fn) {
12161156
$('#tempwidgets').hide(); // TODO delete when multiple views implemented
1157+
$('#temptophtm').hide();
12171158
return ShowNotifications(ctrl.item.idx, escape(ctrl.item.Name), divId, fn);
12181159
};
12191160

12201161
ctrl.ShowForecast = function(divId, fn) {
12211162
$('#tempwidgets').hide(); // TODO delete when multiple views implemented
1163+
$('#temptophtm').hide();
12221164
return ShowForecast(atob(ctrl.item.forecast_url),escape(ctrl.item.Name), divId, fn);
12231165
};
12241166

www/views/temperature.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,32 @@
128128

129129
<div id="tempcontent"></div>
130130

131+
<div id="temptophtm">
132+
<table border="0" cellpadding="0" cellspacing="0" width="100%">
133+
<tr>
134+
<td align="left" valign="top" id="timesun"></td>
135+
<td align="right" valign="top">
136+
<div ng-show="ctrl.RoomPlans.length>0">
137+
<span data-i18n="Room">Room</span>:
138+
<select id="comboroom" style="width:160px" class="combobox ui-corner-all"
139+
ng-model="ctrl.roomSelected" ng-options="room.idx as room.name for room in ctrl.RoomPlans"
140+
ng-change="ctrl.changeRoom()">
141+
</select>
142+
</div>
143+
</td>
144+
</tr>
145+
</table>
146+
<table ng-show="ctrl.isNotMobile()" class="bannav" border="0" cellpadding="0" cellspacing="0" width="100%">
147+
<tr>
148+
<td align="left"></td>
149+
<td align="right">
150+
<a class="btnstyle" onclick="ShowCustomTempLog();" data-i18n="Custom Graph">Custom Graph</a>
151+
<a ng-show="config.Latitude!=''" id="Forecast" class="btnstyle" onclick="ShowForecast();" data-i18n="Forecast">Forecast</a>
152+
</td>
153+
</tr>
154+
</table>
155+
</div>
156+
131157
<div id="tempwidgets" class="row divider">
132158
<h2 ng-show="ctrl.temperatures.length == 0" data-i18n="No Temperature sensors found or added in the system...">No Temperature sensors found or added in the system...</h2>
133159
<div ng-repeat="t in ctrl.temperatures track by t.idx">

0 commit comments

Comments
 (0)