Skip to content

Commit

Permalink
Merge pull request #50 from lbr38/devel
Browse files Browse the repository at this point in the history
3.1.7
  • Loading branch information
lbr38 committed Jan 14, 2024
2 parents b2d4c62 + 06d89f4 commit 2ef803d
Show file tree
Hide file tree
Showing 17 changed files with 510 additions and 381 deletions.
3 changes: 3 additions & 0 deletions www/controllers/Camera.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ public function generateMotionConfiguration(string $id)
$configuration = str_replace('__WIDTH__', $resolution[0], $configuration);
$configuration = str_replace('__HEIGHT__', $resolution[1], $configuration);

/**
* Set username and password for HTTP authentication if specified
*/
if (!empty($camera['Username']) and !empty($camera['Password'])) {
$configuration = preg_replace('/.*netcam_userpass.*/i', 'netcam_userpass ' . $camera['Username'] . ':' . $camera['Password'], $configuration);
}
Expand Down
12 changes: 6 additions & 6 deletions www/controllers/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public static function validateData($data)
/**
* Vérifie que la chaine passée ne contient que des chiffres ou des lettres
*/
public static function isAlphanum(string $data, array $additionnalValidCaracters = [])
public static function isAlphanum(string $data, array $additionalValidCaracters = [])
{
/**
* Si on a passé en argument des caractères supplémentaires à autoriser alors on les ignore dans le test en les remplacant temporairement par du vide
*/
if (!empty($additionnalValidCaracters)) {
if (!ctype_alnum(str_replace($additionnalValidCaracters, '', $data))) {
if (!empty($additionalValidCaracters)) {
if (!ctype_alnum(str_replace($additionalValidCaracters, '', $data))) {
return false;
}

Expand All @@ -94,7 +94,7 @@ public static function isAlphanum(string $data, array $additionnalValidCaracters
* Vérifie que la chaine passée ne contient que des chiffres ou des lettres, un underscore ou un tiret
* Retire temporairement les tirets et underscore de la chaine passée afin qu'elle soit ensuite testée par la fonction PHP ctype_alnum
*/
public static function isAlphanumDash(string $data, array $additionnalValidCaracters = [])
public static function isAlphanumDash(string $data, array $additionalValidCaracters = [])
{
/**
* Si une chaine vide a été transmise alors c'est valide
Expand All @@ -111,8 +111,8 @@ public static function isAlphanumDash(string $data, array $additionnalValidCarac
/**
* Si on a passé en argument des caractères supplémentaires à autoriser alors on les ajoute à l'array $validCaracters
*/
if (!empty($additionnalValidCaracters)) {
$validCaracters = array_merge($validCaracters, $additionnalValidCaracters);
if (!empty($additionalValidCaracters)) {
$validCaracters = array_merge($validCaracters, $additionalValidCaracters);
}

if (!ctype_alnum(str_replace($validCaracters, '', $data))) {
Expand Down
File renamed without changes
48 changes: 25 additions & 23 deletions www/public/resources/js/camera.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$(document).ready(function () {
hideLoading();
hideCameraLoading();
reloadImage();

/**
Expand All @@ -14,7 +14,7 @@ $(document).ready(function () {
/**
* Hide loading div
*/
function hideLoading()
function hideCameraLoading()
{
if (!$('.camera-container').find('.camera-loading')) {
return;
Expand Down Expand Up @@ -159,7 +159,7 @@ $(document).on('submit','#new-camera-form',function () {
// Reload containers:
[ 'getting-started', 'buttons/main', 'cameras/list' ],
// Execute functions :
[ hideLoading() ]
[ hideCameraLoading() ]
);

return false;
Expand Down Expand Up @@ -211,7 +211,7 @@ $(document).on('submit','#camera-global-settings-form',function () {
// Reload containers:
[ 'getting-started', 'buttons/main', 'cameras/list' ],
// Execute functions :
[ hideLoading(), reloadEditForm(id) ]
[ hideCameraLoading(), reloadEditForm(id) ]
);

return false;
Expand All @@ -236,7 +236,7 @@ $(document).on('click','.delete-camera-btn',function () {
// Reload containers:
[ 'getting-started', 'buttons/main', 'cameras/list' ],
// Execute functions :
[ hideLoading() ]
[ hideCameraLoading() ]
);
});
});
Expand Down Expand Up @@ -335,22 +335,24 @@ function getEditForm(id)
*/
function reloadEditForm(id)
{
$.ajax({
type: "POST",
url: "ajax/controller.php",
data: {
controller: "camera",
action: "getEditForm",
id: id
},
dataType: "json",
success: function (data, textStatus, jqXHR) {
jsonValue = jQuery.parseJSON(jqXHR.responseText);
$('#camera-edit-form-container').html(jsonValue.message);
},
error: function (jqXHR, ajaxOptions, thrownError) {
jsonValue = jQuery.parseJSON(jqXHR.responseText);
printAlert(jsonValue.message, 'error');
},
});
setTimeout(function () {
$.ajax({
type: "POST",
url: "ajax/controller.php",
data: {
controller: "camera",
action: "getEditForm",
id: id
},
dataType: "json",
success: function (data, textStatus, jqXHR) {
jsonValue = jQuery.parseJSON(jqXHR.responseText);
$('#camera-edit-form-container').html(jsonValue.message);
},
error: function (jqXHR, ajaxOptions, thrownError) {
jsonValue = jQuery.parseJSON(jqXHR.responseText);
printAlert(jsonValue.message, 'error');
},
});
}, 50);
}
98 changes: 87 additions & 11 deletions www/public/resources/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ function confirmBox(message, myfunction1, confirmBox1 = 'Delete', myfunction2 =
});
}

/**
* Print a veil on specified element by class name, element must be relative
* @param {*} name
*/
function printLoadingVeilByClass(name)
{
$('.' + name).append('<div class="loading-veil"><img src="/assets/images/loading.gif" class="icon" /><span class="lowopacity-cst">Loading</span></div>');
}

/**
* Find all child elements with class .veil-on-reload and print a veil on them, each element must be relative
* @param {*} name
*/
function printLoadingVeilByParentClass(name)
{
$('.' + name).find('.veil-on-reload').append('<div class="loading-veil"><img src="/assets/images/loading.gif" class="icon" /><span class="lowopacity-cst">Loading</span></div>');
}

/**
* Reload content of an element, by its Id
Expand Down Expand Up @@ -179,9 +196,44 @@ function setCookie(cname, cvalue, exdays)
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;Secure";
}

function reloadPanel(panel)
/**
* Reload panel and execute function if needed
* @param {*} panel
* @param {*} myfunction
*/
function reloadPanel(panel, myfunction = null)
{
$(".slide-panel-reloadable-div[slide-panel='" + panel + "']").load(location.href + " .slide-panel-reloadable-div[slide-panel='" + panel + "'] > *");
/**
* Print a loading icon on the bottom of the page
*/
// printLoading();

/**
* Check if panel has children with class .veil-on-reload
* If so print a veil on them
*/
if ($('.slide-panel-reloadable-div[slide-panel="' + panel + '"]').find('.veil-on-reload').length) {
printLoadingVeilByClass('veil-on-reload');
}

$('.slide-panel-reloadable-div[slide-panel="' + panel + '"]').load(' .slide-panel-reloadable-div[slide-panel="' + panel + '"] > *', function () {
/**
* If myfunction is not null, execute it after reloading
*/
if (myfunction != null) {
myfunction();
}

/**
* Reload opened or closed elements that where opened/closed before reloading
*/
reloadOpenedClosedElements();
});

/**
* Hide loading icon
*/
// hideLoading();
}

/**
Expand All @@ -190,14 +242,28 @@ function reloadPanel(panel)
*/
function reloadContainer(container)
{
/**
* Print a loading icon on the bottom of the page
*/
// printLoading();

/**
* Check if container has children with class .veil-on-reload
* If so print a veil on them
*/
if ($('.reloadable-container[container="' + container + '"]').find('.veil-on-reload').length) {
printLoadingVeilByClass('veil-on-reload');
}

$.ajax({
type: "POST",
url: "ajax/controller.php",
url: "/ajax/controller.php",
data: {
sourceUrl: window.location.href,
sourceUri: window.location.pathname,
controller: "general",
action: "getContainer",
container: container,
sourceUri: window.location.pathname,
container: container
},
dataType: "json",
success: function (data, textStatus, jqXHR) {
Expand All @@ -206,12 +272,22 @@ function reloadContainer(container)
* Replace container with itself, with new content
*/
$('.reloadable-container[container="' + container + '"]').replaceWith(jsonValue.message);

/**
* Reload opened or closed elements that were opened/closed before reloading
*/
reloadOpenedClosedElements();
},
error : function (jqXHR, textStatus, thrownError) {
error: function (jqXHR, textStatus, thrownError) {
jsonValue = jQuery.parseJSON(jqXHR.responseText);
printAlert(jsonValue.message, 'error');
},
});

/**
* Hide loading icon
*/
// hideLoading();
}

/**
Expand Down Expand Up @@ -274,10 +350,10 @@ function getContainerState()
* Execute an ajax request
* @param {*} controller
* @param {*} action
* @param {*} additionnalData
* @param {*} additionalData
* @param {*} reloadContainers
*/
function ajaxRequest(controller, action, additionnalData = null, reloadContainers = null, execOnSuccess = null, execOnError = null)
function ajaxRequest(controller, action, additionalData = null, reloadContainers = null, execOnSuccess = null, execOnError = null)
{
/**
* Default data
Expand All @@ -290,10 +366,10 @@ function ajaxRequest(controller, action, additionnalData = null, reloadContainer
};

/**
* If additionnal data is specified, merge it with default data
* If additional data is specified, merge it with default data
*/
if (additionnalData != null) {
data = $.extend(data, additionnalData);
if (additionalData != null) {
data = $.extend(data, additionalData);
}

/**
Expand Down
27 changes: 27 additions & 0 deletions www/public/resources/js/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,33 @@ $(document).on('click','.acquit-log-btn',function () {
acquitLog(id);
});

/**
* Reload opened or closed elements that where opened/closed before reloading
*/
function reloadOpenedClosedElements()
{
/**
* Retrieve sessionStorage with key finishing by /opened (<element>/opened)
*/
var openedElements = Object.keys(sessionStorage).filter(function (key) {
return key.endsWith('/opened');
});

/**
* If there are /opened elements set to true, open them
*/
openedElements.forEach(function (element) {
if (sessionStorage.getItem(element) == 'true') {
var element = element.replace('/opened', '');
$(element).show();
}
if (sessionStorage.getItem(element) == 'false') {
var element = element.replace('/opened', '');
$(element).hide();
}
});
}

/**
* Ajax: Mark log as read
* @param {string} id
Expand Down
Loading

0 comments on commit 2ef803d

Please sign in to comment.