@@ -66,9 +66,19 @@ function getDevices() {
6666 data : null ,
6767 render : function ( data )
6868 {
69- return '<div class="btn-group">'
70- + ' <button class="btn btn-default btn-wol" name="' + data . name + '" mac="' + data . mac + '" + ip="' + data . ip + '" title="Send WoL"><i class="fas fa-power-off"></i></button>'
71- + ' </div>' ;
69+ var btnHtml = '' ;
70+ var wolVisibleClass = "d-none" ;
71+ var shutdownVisibleClass = "d-none" ;
72+ if ( data . shutdownable && data . status ) {
73+ shutdownVisibleClass = "" ;
74+ } else if ( ! data . status ) {
75+ wolVisibleClass = "" ;
76+ }
77+
78+ btnHtml += '<div id="btn-wol-' + data . id + '" class="btn-group ' + wolVisibleClass + '"><button class="btn btn-default btn-wol bg-success" name="' + data . name + '" mac="' + data . mac + '" + ip="' + data . ip + '" title="Send WoL"><i class="fas fa-power-off"></i></button></div>' ;
79+ btnHtml += '<div id="btn-shutdown-' + data . id + '" class="btn-group ' + shutdownVisibleClass + '"><button class="btn btn-default btn-shutdown bg-danger" name="' + data . name + '" mac="' + data . mac + '" + ip="' + data . ip + '" title="Shutdown"><i class="fas fa-power-off"></i></button></div>' ;
80+
81+ return btnHtml ;
7282 } ,
7383 className : 'text-center' ,
7484 searchable : false ,
@@ -97,6 +107,28 @@ function getDevices() {
97107 }
98108 } ) ;
99109 } ) ;
110+
111+ $ ( ".btn-shutdown" ) . unbind ( "click" ) ;
112+ $ ( ".btn-shutdown" ) . click ( function ( ) {
113+ var name = $ ( this ) . attr ( "name" ) ;
114+ var mac = $ ( this ) . attr ( "mac" ) ;
115+ var ip = $ ( this ) . attr ( "ip" ) ;
116+ wolModal = $ . confirm ( {
117+ title : 'Shutdown Confirmation' ,
118+ content : 'Do you want to shut <b>' + name + '</b> down?' ,
119+ type : 'red' ,
120+ typeAnimated : true ,
121+ buttons : {
122+ "Shutdown!" : function ( ) {
123+ shutdown ( name , mac , ip ) ;
124+ wolModal . close ( ) ;
125+ } ,
126+ cancel : function ( ) {
127+ wolModal . close ( ) ;
128+ }
129+ }
130+ } ) ;
131+ } ) ;
100132 } ,
101133 } ) ;
102134}
@@ -108,6 +140,13 @@ function sendWoL(name, mac, ip) {
108140 xhttp . send ( ) ;
109141}
110142
143+ function shutdown ( name , mac , ip ) {
144+ notifyShutdown ( name ) ;
145+ var xhttp = new XMLHttpRequest ( ) ;
146+ xhttp . open ( "GET" , "./shutdown/" + ip , true ) ;
147+ xhttp . send ( ) ;
148+ }
149+
111150function notifyWoL ( name ) {
112151 toastr . options = {
113152 "closeButton" : false ,
@@ -129,16 +168,43 @@ function notifyWoL(name){
129168 toastr [ "success" ] ( "Turning " + name + " on." , "WoL Sent" )
130169}
131170
171+ function notifyShutdown ( name ) {
172+ toastr . options = {
173+ "closeButton" : false ,
174+ "debug" : false ,
175+ "newestOnTop" : false ,
176+ "progressBar" : false ,
177+ "positionClass" : "toast-top-center" ,
178+ "preventDuplicates" : false ,
179+ "onclick" : null ,
180+ "showDuration" : "300" ,
181+ "hideDuration" : "1000" ,
182+ "timeOut" : "5000" ,
183+ "extendedTimeOut" : "1000" ,
184+ "showEasing" : "swing" ,
185+ "hideEasing" : "linear" ,
186+ "showMethod" : "fadeIn" ,
187+ "hideMethod" : "fadeOut"
188+ }
189+ toastr [ "error" ] ( "Turning " + name + " off." , "Shutdown Sent" )
190+ }
191+
132192function threadGetDevices ( ) {
133193 window . setInterval ( function ( ) {
134194 httpGetAsync ( "/getDevices" , function ( devices ) {
135195 var devices = JSON . parse ( devices ) ;
136196 if ( devices != null && devices . length > 0 ) {
137197 devices . forEach ( function callback ( device , index , array ) {
198+ $ ( "#btn-wol-" + device . id ) . addClass ( "d-none" ) ;
199+ $ ( "#btn-shutdown-" + device . id ) . addClass ( "d-none" ) ;
138200 if ( device . status ) {
139201 $ ( "#img" + device . id ) . attr ( "src" , "/img/online.png" ) ;
140- } else {
202+ if ( device . shutdownable ) {
203+ $ ( "#btn-shutdown-" + device . id ) . removeClass ( "d-none" ) ;
204+ }
205+ } else if ( ! device . status ) {
141206 $ ( "#img" + device . id ) . attr ( "src" , "/img/offline.png" ) ;
207+ $ ( "#btn-wol-" + device . id ) . removeClass ( "d-none" ) ;
142208 }
143209 } ) ;
144210 }
0 commit comments