Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/nextcloudpi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornacho <nacho@ownyourbits.com>2018-12-31 04:00:01 +0300
committernachoparker <nacho@ownyourbits.com>2019-01-05 04:14:53 +0300
commit7864c3a3fcf6fe0dbfd9ea2f0f46ad0681c2ef8a (patch)
tree32d6818b21e0bb3e68d05f251e42637b4edd8168 /ncp-web
parent80cd216eac90642e54f6980eae30ff6dd5005001 (diff)
add path exists
Diffstat (limited to 'ncp-web')
-rw-r--r--ncp-web/elements.php7
-rw-r--r--ncp-web/js/ncp.js37
-rw-r--r--ncp-web/ncp-launcher.php15
3 files changed, 58 insertions, 1 deletions
diff --git a/ncp-web/elements.php b/ncp-web/elements.php
index ea2b4b65..52c50844 100644
--- a/ncp-web/elements.php
+++ b/ncp-web/elements.php
@@ -33,10 +33,15 @@ HTML;
if (array_key_exists('default', $param))
$default = $param['default'];
+ $class = '';
+ if ($param['type'] == 'directory' || $param['type'] == 'file')
+ $class = 'path';
+
$ret .= "<td>
<input type=\"text\"
- name=\"$param[name]\"
id=\"$ncp_app-$param[id]\"
+ name=\"$param[name]\"
+ class=\"$class\"
value=\"$param[value]\"
default=\"$default\"
placeholder=\"$suggest\"
diff --git a/ncp-web/js/ncp.js b/ncp-web/js/ncp.js
index e94c29c0..5e85bad3 100644
--- a/ncp-web/js/ncp.js
+++ b/ncp-web/js/ncp.js
@@ -268,6 +268,43 @@ $(function()
input.set('.value', input.get('@default'));
});
+ // Path fields
+ $( '.path' ).on('|keydown', function(e)
+ {
+ var span = this.up().select('span', true);
+ span.fill();
+ }
+ );
+
+ // Path fields
+ $( '.path' ).on('change', function(e)
+ {
+ var span = this.up().select('span', true);
+ // request
+ $.request('post', 'ncp-launcher.php', { action:'path-exists',
+ value: this.get('.value'),
+ csrf_token: $( '#csrf-token-cfg' ).get( '.value' ) }).then(
+ function success( result )
+ {
+ var ret = $.parseJSON( result );
+ if ( ret.token )
+ $('#csrf-token-cfg').set( { value: ret.token } );
+ if ( ret.ret && ret.ret == '0' ) // means that the process was launched
+ {
+ span.fill("path exists")
+ span.set('-error-field');
+ span.set('+ok-field');
+ }
+ else
+ {
+ span.fill("path doesn't exist")
+ span.set('-ok-field');
+ span.set('+error-field');
+ }
+ }
+ ).error( errorMsg )
+ } );
+
// Update notification
$( '#notification' ).on('click', function(e)
{
diff --git a/ncp-web/ncp-launcher.php b/ncp-web/ncp-launcher.php
index 4d720ced..8590b066 100644
--- a/ncp-web/ncp-launcher.php
+++ b/ncp-web/ncp-launcher.php
@@ -148,6 +148,21 @@ else if ( $_POST['action'] == "cfg-ui" )
}
//
+// path field
+//
+else if ( $_POST['action'] == "path-exists" )
+{
+ if (file_exists($_POST['value']))
+ $ret = 0;
+ else
+ $ret = 1;
+
+ // return JSON
+ echo '{ "token": "' . getCSRFToken() . '",'; // Get new token
+ echo ' "ret": "' . $ret . '" }';
+}
+
+//
// poweroff
//
else if ( $_POST['action'] == "poweroff" )