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:
Diffstat (limited to 'ncp-activation/JS.js')
-rw-r--r--ncp-activation/JS.js124
1 files changed, 124 insertions, 0 deletions
diff --git a/ncp-activation/JS.js b/ncp-activation/JS.js
new file mode 100644
index 00000000..3432dbe1
--- /dev/null
+++ b/ncp-activation/JS.js
@@ -0,0 +1,124 @@
+///
+// NextCloudPi Web Panel javascript library
+//
+// Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
+// GPL licensed (see end of file) * Use at your own risk!
+//
+// More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/
+///
+
+var MINI = require('minified');
+var $ = MINI.$, $$ = MINI.$$, EE = MINI.EE;
+var selectedID = null;
+var confLock = false;
+
+function errorMsg()
+{
+ $('#error-box').fill( "Something went wrong. Try refreshing the page" );
+}
+
+function launch_nc_passwd()
+{
+ // request
+ $.request('post', '../ncp-launcher.php', { action: 'launch',
+ ref : 'nc-passwd',
+ config: '{ "PASSWORD":"' + $('#ncp-pwd').get('.value') + '",'
+ + '"CONFIRM" :"' + $('#ncp-pwd').get('.value') + '"}',
+ csrf_token: $( '#csrf-token' ).get( '.value' ) }).then(
+
+ function success( result )
+ {
+ var ret = $.parseJSON( result );
+ if ( ret.ret == '0' )
+ {
+ setTimeout( function(){
+ $('#loading-gif').hide();
+ $('#error-box').fill( "ACTIVATION SUCCESSFUL" );
+ var url = window.location.protocol + '//' + window.location.hostname + ':4443';
+ if ( !window.open( url, '_blank' ) ) // try to open in a new tab first
+ window.location.replace( url );
+ }, 4000 );
+ } else {
+ $('#error-box').fill( "nc-passwd error" );
+ }
+ } ).error( errorMsg );
+}
+
+function nc_admin_ok_cb( result )
+{
+ var ret = $.parseJSON( result );
+ if ( ret.token )
+ $('#csrf-token').set( { value: ret.token } );
+ if ( ret.ret == '0' ) {
+ launch_nc_passwd();
+ } else {
+ $('#error-box').fill( "NextCloudPi not yet initialized, trying again in a few seconds ..." );
+ setTimeout( launch_activation, 10000 );
+ }
+}
+
+function launch_activation()
+{
+ // request
+ $.request('post', '../ncp-launcher.php', { action: 'launch',
+ ref : 'nc-admin',
+ config: '{ "PASSWORD":"' + $('#nc-pwd').get('.value') + '",'
+ + '"CONFIRM" :"' + $('#nc-pwd').get('.value') + '",'
+ + '"USER" : "ncp" }',
+ csrf_token: $( '#csrf-token' ).get( '.value' ) }
+ ).then( nc_admin_ok_cb ).error( errorMsg );
+}
+
+$(function()
+{
+ // print info page
+ $( '#print-pwd' ).on( 'click', function(e) { window.print(); } );
+
+ // copy to clipboard
+ $( '#cp-ncp' ).on( 'click', function(e)
+ {
+ var input = document.getElementById('ncp-pwd');
+ input.focus();
+ input.select();
+ var res =document.execCommand( 'copy' );
+ $('#cp-ncp-ok').fill( res ? "✓" : "✘" );
+ input.selectionStart = input.selectionEnd;
+ } );
+
+ // copy to clipboard
+ $( '#cp-nc' ).on( 'click', function(e)
+ {
+ var input = document.getElementById('nc-pwd');
+ input.focus();
+ input.select();
+ var res =document.execCommand( 'copy' );
+ $('#cp-nc-ok').fill( res ? "✓" : "✘" );
+ input.selectionStart = input.selectionEnd;
+ } );
+
+ // activate NextCloudPi
+ $( '#activate-ncp' ).on( 'click', function(e)
+ {
+ $( '#activate-ncp' ).hide();
+ $( '#print-pwd' ).hide();
+ $('#loading-gif').set( { $display: 'inline' } );
+ launch_activation();
+ } );
+} );
+
+// License
+//
+// This script is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This script is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this script; if not, write to the
+// Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+// Boston, MA 02111-1307 USA