diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ce467330a..e72fb09bb 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -51,13 +51,19 @@ jobs: # Prefix the list here with "+" to use these queries and those in the config file. # queries: ./path/to/local/query, your-org/your-repo/queries@main + - name: Clean install dependencies and build + run: | + git submodule init + git submodule update --init --recursive + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild uses: github/codeql-action/autobuild@v1 # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl + # 📚 https://git.io/JvXDl- + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines # and modify them (or add more) to build your code if your project diff --git a/web/ajax/modals/device.php b/web/ajax/modals/device.php new file mode 100644 index 000000000..5a29785ef --- /dev/null +++ b/web/ajax/modals/device.php @@ -0,0 +1,54 @@ + "", + "Name" => "New Device", + "KeyString" => "" + ); +} + +?> + diff --git a/web/includes/actions/device.php b/web/includes/actions/device.php index c1a882d89..29011dd73 100644 --- a/web/includes/actions/device.php +++ b/web/includes/actions/device.php @@ -28,15 +28,17 @@ if ( $action == 'device' ) { if ( !empty($_REQUEST['command']) ) { setDeviceStatusX10($_REQUEST['key'], $_REQUEST['command']); } else if ( isset($_REQUEST['newDevice']) ) { - if ( isset($_REQUEST['did']) ) { + if ( isset($_REQUEST['did']) && $_REQUEST['did'] ) { + ZM\Warning('did value is: '.$_REQUEST['did']); + ZM\Warning('newDevice array value is: '.print_r($_REQUEST['newDevice'],true)); dbQuery('UPDATE Devices SET Name=?, KeyString=? WHERE Id=?', array($_REQUEST['newDevice']['Name'], $_REQUEST['newDevice']['KeyString'], $_REQUEST['did']) ); } else { + dbQuery('INSERT INTO Devices SET Name=?, KeyString=?', array($_REQUEST['newDevice']['Name'], $_REQUEST['newDevice']['KeyString']) ); } - $refreshParent = true; - $view = 'none'; + $redirect = '?view=devices'; } } else { ZM\Error('Unknown action in device'); diff --git a/web/skins/classic/views/device.php b/web/skins/classic/views/device.php deleted file mode 100644 index fa1a6a9d4..000000000 --- a/web/skins/classic/views/device.php +++ /dev/null @@ -1,67 +0,0 @@ - "", - "Name" => "New Device", - "KeyString" => "" - ); -} - -xhtmlHeaders( __FILE__, translate('Device')." - ".$newDevice['Name'] ); -?> - -
- -
-
- - - - - - - - - - - - - - -
-
- disabled="disabled"/> -
-
-
-
- - diff --git a/web/skins/classic/views/devices.php b/web/skins/classic/views/devices.php index 783d7775a..4a0688d70 100644 --- a/web/skins/classic/views/devices.php +++ b/web/skins/classic/views/devices.php @@ -35,9 +35,16 @@ foreach( dbFetchAll( $sql ) as $row ) xhtmlHeaders(__FILE__, translate('Devices') ); ?> +
- - - + diff --git a/web/skins/classic/views/js/devices.js b/web/skins/classic/views/js/devices.js index 703384ad2..eb7810b0f 100644 --- a/web/skins/classic/views/js/devices.js +++ b/web/skins/classic/views/js/devices.js @@ -1,3 +1,5 @@ +var newDeviceBtn = $j('#newDeviceBtn'); + function switchDeviceOn( element, key ) { var form = element.form; form.view.value = currentView; @@ -37,4 +39,56 @@ function configureButtons( element, name ) { form.deleteBtn.disabled = !checked; } -window.focus(); +// Load the Device Modal HTML via Ajax call +function getDeviceModal(did) { + $j.getJSON(thisUrl + '?request=modal&modal=device&did=' + did) + .done(function(data) { + if ( $j('#deviceModal').length ) { + $j('#deviceModal').replaceWith(data.html); + } else { + $j("body").append(data.html); + } + $j('#deviceModal').modal('show'); + // Manage the Save button + $j('#deviceSaveBtn').click(function(evt) { + evt.preventDefault(); + $j('#deviceModalForm').submit(); + }); + }) + .fail(logAjaxFail); +} + +function enableDeviceModal() { + $j(".deviceCol").click(function(evt) { + evt.preventDefault(); + var did = $j(this).data('did'); + getDeviceModal(did); + }); + newDeviceBtn.click(function(evt) { + evt.preventDefault(); + getDeviceModal(0); + }); +} + +function initPage() { + if ( canEditDevice ) enableDeviceModal(); + + newDeviceBtn.prop('disabled', !canEditDevice); + + // Manage the BACK button + document.getElementById("backBtn").addEventListener("click", function onBackClick(evt) { + evt.preventDefault(); + window.history.back(); + }); + + // Disable the back button if there is nothing to go back to + $j('#backBtn').prop('disabled', !document.referrer.length); + + // Manage the REFRESH Button + document.getElementById("refreshBtn").addEventListener("click", function onRefreshClick(evt) { + evt.preventDefault(); + window.location.reload(true); + }); +} + +$j(document).ready(initPage); diff --git a/web/skins/classic/views/js/devices.js.php b/web/skins/classic/views/js/devices.js.php new file mode 100644 index 000000000..f80541494 --- /dev/null +++ b/web/skins/classic/views/js/devices.js.php @@ -0,0 +1 @@ +var canEditDevice = ;