diff options
author | nachoparker <nacho@ownyourbits.com> | 2019-01-07 03:58:41 +0300 |
---|---|---|
committer | nachoparker <nacho@ownyourbits.com> | 2019-01-07 04:43:09 +0300 |
commit | 1a056212f17a20cbfccb6a68fb7439088128d352 (patch) | |
tree | c1c3a27051566f5edf27740f7a6391f12e302ba2 /ncp-web | |
parent | bda1fc468d072c9cf94ef55dc4febd597b22748b (diff) |
ncp-web: file type and case insensitive search
Diffstat (limited to 'ncp-web')
-rw-r--r-- | ncp-web/elements.php | 16 | ||||
-rw-r--r-- | ncp-web/js/ncp.js | 43 |
2 files changed, 52 insertions, 7 deletions
diff --git a/ncp-web/elements.php b/ncp-web/elements.php index 0541db93..ab475784 100644 --- a/ncp-web/elements.php +++ b/ncp-web/elements.php @@ -36,7 +36,7 @@ HTML; $class = ''; if (array_key_exists('type', $param) && ($param['type'] == 'directory' || $param['type'] == 'file')) - $class = 'path'; + $class = $param['type']; $ret .= "<td> <input type=\"text\" @@ -54,9 +54,19 @@ HTML; if (array_key_exists('type', $param) && $param['type'] == 'directory') { if (file_exists($param['value'])) - $ret .= " <span class=\"ok-field\">directory exists</span>"; + $ret .= " <span class=\"ok-field\">path exists</span>"; else - $ret .= " <span class=\"error-field\">directory doesn't exist</span>"; + $ret .= " <span class=\"error-field\">path doesn't exist</span>"; + } + + if (array_key_exists('type', $param) && $param['type'] == 'file') + { + error_log($param['value']); + error_log(dirname($param['value'])); + if (file_exists(dirname($param['value']))) + $ret .= " <span class=\"ok-field\">path exists</span>"; + else + $ret .= " <span class=\"error-field\">path doesn't exist</span>"; } $ret .= "</td>"; diff --git a/ncp-web/js/ncp.js b/ncp-web/js/ncp.js index 4a5d1789..8db1ebd4 100644 --- a/ncp-web/js/ncp.js +++ b/ncp-web/js/ncp.js @@ -152,7 +152,8 @@ function filter_apps(e) { if (e && e.key === 'Enter') { - var match = ncp_app_list.find(function(app) { if (app.id.indexOf(search_box.value) !== -1) return app; }); + if (search_box.value.length == 0 ) return; + var match = ncp_app_list.find(function(app) { if (app.id.toLowerCase().indexOf(search_box.value.toLowerCase()) !== -1) return app; }); if (!match) return; app_clicked($('#' + match.id)); ncp_app_list.show(); @@ -167,7 +168,7 @@ function filter_apps(e) ncp_app_list.hide(); ncp_app_list.each( function(app){ - if (app.id.indexOf(search_box.value) !== -1) + if (app.id.toLowerCase().indexOf(search_box.value.toLowerCase()) !== -1) app.style.display = 'block'; } ); @@ -303,12 +304,46 @@ $(function() ); // Path fields - $( '.path' ).on('change', function(e) + $('.directory').on('change', function(e) { var span = this.up().select('span', true); + var path = this.get('.value'); + + // request + $.request('post', 'ncp-launcher.php', { action:'path-exists', + value: path, + 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 ) + } ); + $('.file').on('change', function(e) + { + function dirname(path) { return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, ''); } + + var span = this.up().select('span', true); + console.log(span); + var path = dirname(this.get('.value')); + // request $.request('post', 'ncp-launcher.php', { action:'path-exists', - value: this.get('.value'), + value: path, csrf_token: $('#csrf-token-cfg').get('.value') }).then( function success( result ) { |