1
1
define ( [ 'app' ] , function ( app ) {
2
- app . controller ( 'LightsController' , [ '$scope' , '$rootScope' , '$location' , '$http' , '$interval' , 'permissions' , function ( $scope , $rootScope , $location , $http , $interval , permissions ) {
2
+ app . controller ( 'LightsController' , function ( $scope , $rootScope , $location , $http , $interval , $route , $routeParams , permissions ) {
3
+ var $element = $ ( '#main-view #lightcontent' ) . last ( ) ;
4
+
3
5
$scope . HasInitializedAddManualDialog = false ;
4
6
5
7
MakeFavorite = function ( id , isfavorite ) {
@@ -849,9 +851,10 @@ define(['app'], function (app) {
849
851
850
852
var i = 0 ;
851
853
var j = 0 ;
854
+ var roomPlanId = $routeParams . room || window . myglobals . LastPlanSelected ;
852
855
853
856
$ . ajax ( {
854
- url : "json.htm?type=devices&filter=light&used=true&order=[Order]&plan=" + window . myglobals . LastPlanSelected ,
857
+ url : "json.htm?type=devices&filter=light&used=true&order=[Order]&plan=" + roomPlanId ,
855
858
async : false ,
856
859
dataType : 'json' ,
857
860
success : function ( data ) {
@@ -1401,28 +1404,33 @@ define(['app'], function (app) {
1401
1404
htmlcontent = '<h2>' + $ . t ( 'No Lights/Switches found or added in the system...' ) + '</h2>' ;
1402
1405
}
1403
1406
$ ( '#modal' ) . hide ( ) ;
1404
- $ ( '#lightcontent' ) . html ( tophtm + htmlcontent ) ;
1405
- $ ( '#lightcontent' ) . i18n ( ) ;
1407
+ $element . html ( tophtm + htmlcontent ) ;
1408
+ $element . i18n ( ) ;
1406
1409
if ( bShowRoomplan == true ) {
1407
1410
$ . each ( $ . RoomPlans , function ( i , item ) {
1408
1411
var option = $ ( '<option />' ) ;
1409
1412
option . attr ( 'value' , item . idx ) . text ( item . name ) ;
1410
- $ ( "#lightcontent #comboroom") . append ( option ) ;
1413
+ $element . find ( " #comboroom") . append ( option ) ;
1411
1414
} ) ;
1412
- if ( typeof window . myglobals . LastPlanSelected != 'undefined' ) {
1413
- $ ( "#lightcontent # comboroom" ) . val ( window . myglobals . LastPlanSelected ) ;
1415
+ if ( typeof roomPlanId != 'undefined' ) {
1416
+ $element . find ( "#comboroom" ) . val ( roomPlanId ) ;
1414
1417
}
1415
- $ ( "#lightcontent #comboroom") . change ( function ( ) {
1416
- var idx = $ ( "#lightcontent #comboroom option:selected") . val ( ) ;
1418
+ $element . find ( " #comboroom") . change ( function ( ) {
1419
+ var idx = $element . find ( " #comboroom option:selected") . val ( ) ;
1417
1420
window . myglobals . LastPlanSelected = idx ;
1418
- ShowLights ( ) ;
1421
+
1422
+ $route . updateParams ( {
1423
+ room : idx > 0 ? idx : undefined
1424
+ } ) ;
1425
+ $location . replace ( ) ;
1426
+ $scope . $apply ( ) ;
1419
1427
} ) ;
1420
1428
}
1421
1429
1422
1430
if ( $scope . config . AllowWidgetOrdering == true ) {
1423
1431
if ( permissions . hasPermission ( "Admin" ) ) {
1424
1432
if ( window . myglobals . ismobileint == false ) {
1425
- $ ( "#lightcontent .span4") . draggable ( {
1433
+ $element . find ( " .span4") . draggable ( {
1426
1434
drag : function ( ) {
1427
1435
if ( typeof $scope . mytimer != 'undefined' ) {
1428
1436
$interval . cancel ( $scope . mytimer ) ;
@@ -1433,10 +1441,10 @@ define(['app'], function (app) {
1433
1441
} ,
1434
1442
revert : true
1435
1443
} ) ;
1436
- $ ( "#lightcontent .span4") . droppable ( {
1444
+ $element . find ( " .span4") . droppable ( {
1437
1445
drop : function ( ) {
1438
1446
var myid = $ ( this ) . attr ( "id" ) ;
1439
- var roomid = $ ( "#lightcontent #comboroom option:selected") . val ( ) ;
1447
+ var roomid = $element . find ( " #comboroom option:selected") . val ( ) ;
1440
1448
if ( typeof roomid == 'undefined' ) {
1441
1449
roomid = 0 ;
1442
1450
}
@@ -1456,7 +1464,7 @@ define(['app'], function (app) {
1456
1464
$rootScope . RefreshTimeAndSun ( ) ;
1457
1465
1458
1466
//Create Dimmer Sliders
1459
- $ ( '#lightcontent .dimslider') . slider ( {
1467
+ $element . find ( ' .dimslider') . slider ( {
1460
1468
//Config
1461
1469
range : "min" ,
1462
1470
min : 0 ,
@@ -1527,7 +1535,7 @@ define(['app'], function (app) {
1527
1535
$scope . ResizeDimSliders ( ) ;
1528
1536
1529
1537
//Create Selector selectmenu
1530
- $ ( '#lightcontent .selectorlevels select') . selectmenu ( {
1538
+ $element . find ( ' .selectorlevels select') . selectmenu ( {
1531
1539
//Config
1532
1540
width : '75%' ,
1533
1541
value : 0 ,
@@ -1545,7 +1553,7 @@ define(['app'], function (app) {
1545
1553
select$ . selectmenu ( "menuWidget" ) . addClass ( 'selectorlevels-menu' ) ;
1546
1554
select$ . val ( level ) ;
1547
1555
1548
- $ ( '#lightcontent #' + idx + " #bigtext" ) . html ( unescape ( levelname ) ) ;
1556
+ $element . find ( ' #' + idx + " #bigtext" ) . html ( unescape ( levelname ) ) ;
1549
1557
} ,
1550
1558
change : function ( event , ui ) { //When the user selects an option
1551
1559
var select$ = $ ( this ) ,
@@ -1568,13 +1576,13 @@ define(['app'], function (app) {
1568
1576
}
1569
1577
1570
1578
$scope . ResizeDimSliders = function ( ) {
1571
- var nobj = $ ( "#lightcontent #name") ;
1579
+ var nobj = $element . find ( " #name") ;
1572
1580
if ( typeof nobj == 'undefined' ) {
1573
1581
return ;
1574
1582
}
1575
1583
var width = nobj . width ( ) - 50 ;
1576
- $ ( "#lightcontent .dimslider") . width ( width ) ;
1577
- $ ( "#lightcontent .dimsmall") . width ( width - 48 ) ;
1584
+ $element . find ( " .dimslider") . width ( width ) ;
1585
+ $element . find ( " .dimsmall") . width ( width - 48 ) ;
1578
1586
}
1579
1587
1580
1588
$ . strPad = function ( i , l , s ) {
@@ -2368,6 +2376,7 @@ define(['app'], function (app) {
2368
2376
2369
2377
ShowLights ( ) ;
2370
2378
} ;
2379
+
2371
2380
$scope . $on ( '$destroy' , function ( ) {
2372
2381
if ( typeof $scope . mytimer != 'undefined' ) {
2373
2382
$interval . cancel ( $scope . mytimer ) ;
@@ -2383,5 +2392,5 @@ define(['app'], function (app) {
2383
2392
popup . hide ( ) ;
2384
2393
}
2385
2394
} ) ;
2386
- } ] ) ;
2395
+ } ) ;
2387
2396
} ) ;
0 commit comments