1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 21:29:42 +02:00
documize/gui/app/components/onboard/share-folder.js

135 lines
5 KiB
JavaScript
Raw Normal View History

2016-07-07 18:54:16 -07:00
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
2016-10-16 19:26:20 +01:00
// This software (Documize Community Edition) is licensed under
2016-07-07 18:54:16 -07:00
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
2016-10-16 19:26:20 +01:00
// by contacting <sales@documize.com>.
2016-07-07 18:54:16 -07:00
//
// https://documize.com
import $ from 'jquery';
import { inject as service } from '@ember/service';
import Component from '@ember/component';
export default Component.extend({
folderService: service('folder'),
2016-07-07 18:54:16 -07:00
serial: "",
folderId: "",
slug: "",
processing: false,
2022-03-04 18:31:23 -05:00
didRender(...args) {
this._super(...args);
2016-07-07 18:54:16 -07:00
let self = this;
$("#stage-1-firstname").focus();
// Stage 1 - person name keypress handler
$("#stage-1-firstname, #stage-1-lastname").keyup(function() {
if (!$("#stage-1-firstname").val() || !$("#stage-1-lastname").val()) {
2016-10-16 19:26:20 +01:00
$(".name-status").attr("src", "/assets/img/onboard/person-red.png");
2016-07-07 18:54:16 -07:00
} else {
2016-10-16 19:26:20 +01:00
$(".name-status").attr("src", "/assets/img/onboard/person-green.png");
2016-07-07 18:54:16 -07:00
}
});
// Stage 1 - finish
$("#stage-1-next").off('click').on('click', function() {
if (!$("#stage-1-firstname").val()) {
$("#stage-1-firstname").focus();
2017-11-27 19:33:42 +00:00
$("#stage-1-firstname").addClass("is-invalid");
2016-10-16 19:26:20 +01:00
$(".name-status").attr("src", "/assets/img/onboard/person-red.png");
2016-07-07 18:54:16 -07:00
return;
}
2017-11-27 19:33:42 +00:00
$("#stage-1-firstname").removeClass("is-invalid");
2016-07-07 18:54:16 -07:00
if (!$("#stage-1-lastname").val()) {
$("#stage-1-lastname").focus();
2017-11-27 19:33:42 +00:00
$("#stage-1-lastname").addClass("is-invalid");
2016-10-16 19:26:20 +01:00
$(".name-status").attr("src", "/assets/img/onboard/person-red.png");
2016-07-07 18:54:16 -07:00
return;
}
2017-11-27 19:33:42 +00:00
$("#stage-1-lastname").removeClass("is-invalid");
2016-07-07 18:54:16 -07:00
self.set('processing', false);
$(".stage-1").fadeOut("slow", function() {
if (self.get('processing')) {
return;
}
self.set('processing', true);
$(".stage-2").fadeIn();
$("#stage-2-password").focus();
// Stage 2 - password keypress handler
$("#stage-2-password-confirm").keyup(function() {
if ($("#stage-2-password").val().length < 6 || $("#stage-2-password").val().length > 50 ||
($("#stage-2-password").val() !== $("#stage-2-password-confirm").val())) {
2017-11-27 19:33:42 +00:00
// $(".password-status").attr("src", "/assets/img/onboard/lock-red.png");
2016-07-07 18:54:16 -07:00
} else {
2017-11-27 19:33:42 +00:00
// $(".password-status").attr("src", "/assets/img/onboard/lock-green.png");
2016-07-07 18:54:16 -07:00
}
});
});
});
// Stage 2 - finish
$("#stage-2-next").off('click').on('click', function() {
if (!$("#stage-2-password").val() || $("#stage-2-password").val().length < 6 || $("#stage-2-password").val().length > 50) {
$("#stage-2-password").focus();
2017-11-27 19:33:42 +00:00
$("#stage-2-password").addClass("is-invalid");
2016-07-07 18:54:16 -07:00
return;
}
2017-11-27 19:33:42 +00:00
$("#stage-2-password").removeClass("is-invalid");
2016-07-07 18:54:16 -07:00
if (!$("#stage-2-password-confirm").val()) {
$("#stage-2-password-confirm").focus();
2017-11-27 19:33:42 +00:00
$("#stage-2-password-confirm").addClass("is-invalid");
2016-07-07 18:54:16 -07:00
return;
}
if ($("#stage-2-password-confirm").val() !== $("#stage-2-password").val()) {
2018-12-13 13:34:26 +00:00
$("#stage-2-password").addClass("is-invalid");
$("#stage-2-password-confirm").addClass("is-invalid");
2016-07-07 18:54:16 -07:00
return;
}
2018-12-13 13:34:26 +00:00
$("#stage-2-password").removeClass("is-invalid");
2017-11-27 19:33:42 +00:00
$("#stage-2-password-confirm").removeClass("is-invalid");
2016-07-07 18:54:16 -07:00
self.set('processing', false);
$(".stage-2").fadeOut("slow", function() {
if (self.get('processing')) {
return;
}
self.set('processing', true);
$(".stage-3").fadeIn();
var payload = '{ "password": "' + $("#stage-2-password").val() + '", "serial": "' + self.serial + '", "firstname": "' + $("#stage-1-firstname").val() + '", "lastname": "' + $("#stage-1-lastname").val() + '" }';
2016-07-07 18:54:16 -07:00
var password = $("#stage-2-password").val();
self.get('folderService').onboard(self.folderId, payload).then(function(user) {
let creds = { password: password, email: user.email };
self.get('session').authenticate('authenticator:documize', creds).then(() => {
window.location.href = '//' + window.location.host + '/s/' + self.folderId + "/" + self.slug;
2016-07-07 18:54:16 -07:00
});
}, function() {
window.location.href = "/";
});
});
});
},
2016-10-16 19:26:20 +01:00
});