2016-08-01 15:07:46 +02:00
|
|
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
|
|
//
|
|
|
|
// This software (Documize Community Edition) is licensed under
|
|
|
|
// 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
|
|
|
|
// by contacting <sales@documize.com>.
|
|
|
|
//
|
|
|
|
// https://documize.com
|
|
|
|
|
2017-11-16 13:28:05 +00:00
|
|
|
import $ from 'jquery';
|
2017-11-28 12:27:50 +00:00
|
|
|
import { empty, and } from '@ember/object/computed';
|
2017-11-16 13:28:05 +00:00
|
|
|
import { isEmpty } from '@ember/utils';
|
|
|
|
import { set } from '@ember/object';
|
2018-11-24 18:39:43 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2018-06-05 14:04:14 +01:00
|
|
|
import Notifier from '../../mixins/notifier';
|
|
|
|
import Component from '@ember/component';
|
2017-11-16 13:28:05 +00:00
|
|
|
|
2018-06-05 14:04:14 +01:00
|
|
|
export default Component.extend(Notifier, {
|
2018-11-24 18:39:43 +00:00
|
|
|
appMeta: service(),
|
2019-02-27 13:49:59 +00:00
|
|
|
router: service(),
|
2018-07-05 12:02:10 -04:00
|
|
|
maxTags: 3,
|
2019-02-27 13:49:59 +00:00
|
|
|
domain: '',
|
2017-11-16 13:28:05 +00:00
|
|
|
titleEmpty: empty('model.general.title'),
|
|
|
|
messageEmpty: empty('model.general.message'),
|
|
|
|
conversionEndpointEmpty: empty('model.general.conversionEndpoint'),
|
|
|
|
hasTitleInputError: and('titleEmpty', 'titleError'),
|
|
|
|
hasMessageInputError: and('messageEmpty', 'messageError'),
|
|
|
|
hasConversionEndpointInputError: and('conversionEndpointEmpty', 'conversionEndpointError'),
|
2016-07-27 13:18:57 +02:00
|
|
|
|
2018-07-05 12:02:10 -04:00
|
|
|
didReceiveAttrs() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.set('maxTags', this.get('model.general.maxTags'));
|
2019-02-27 13:49:59 +00:00
|
|
|
this.set('domain', this.get('model.general.domain'));
|
2018-07-05 12:02:10 -04:00
|
|
|
},
|
|
|
|
|
2019-01-06 13:50:12 +00:00
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
let url = this.get('appMeta.endpoint');
|
|
|
|
let orgId = this.get('appMeta.orgId');
|
|
|
|
let uploadUrl = `${url}/organization/${orgId}/logo`;
|
|
|
|
|
2019-02-05 20:26:47 +00:00
|
|
|
// Handle upload clicks on button and anything inside that button.
|
|
|
|
let sel = ['#upload-logo', '#upload-logo > div'];
|
|
|
|
for (var i=0; i < 2; i++) {
|
|
|
|
let dzone = new Dropzone(sel[i], {
|
|
|
|
headers: {
|
|
|
|
'Authorization': 'Bearer ' + self.get('session.authToken')
|
|
|
|
},
|
|
|
|
url: uploadUrl,
|
|
|
|
method: "post",
|
|
|
|
paramName: 'attachment',
|
|
|
|
clickable: true,
|
|
|
|
maxFilesize: 50,
|
|
|
|
parallelUploads: 1,
|
|
|
|
uploadMultiple: false,
|
|
|
|
addRemoveLinks: false,
|
|
|
|
autoProcessQueue: true,
|
|
|
|
createImageThumbnails: false,
|
2019-01-06 13:50:12 +00:00
|
|
|
|
2019-02-05 20:26:47 +00:00
|
|
|
init: function () {
|
|
|
|
this.on("success", function (/*file, response*/ ) {
|
|
|
|
});
|
2019-01-06 13:50:12 +00:00
|
|
|
|
2019-02-05 20:26:47 +00:00
|
|
|
this.on("queuecomplete", function () {
|
|
|
|
self.notifySuccess('Logo uploaded');
|
|
|
|
});
|
2019-01-06 13:50:12 +00:00
|
|
|
|
2019-02-05 20:26:47 +00:00
|
|
|
this.on("error", function (error, msg) {
|
|
|
|
self.notifyError(msg);
|
|
|
|
self.notifyError(error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2019-01-06 13:50:12 +00:00
|
|
|
|
2019-02-05 20:26:47 +00:00
|
|
|
dzone.on("complete", function (file) {
|
|
|
|
dzone.removeFile(file);
|
|
|
|
});
|
|
|
|
}
|
2019-01-06 13:50:12 +00:00
|
|
|
},
|
|
|
|
|
2016-07-27 13:18:57 +02:00
|
|
|
actions: {
|
2018-07-05 12:02:10 -04:00
|
|
|
change() {
|
|
|
|
const selectEl = this.$('#maxTags')[0];
|
|
|
|
const selection = selectEl.selectedOptions[0].value;
|
|
|
|
|
|
|
|
this.set('maxTags', parseInt(selection));
|
|
|
|
},
|
|
|
|
|
2016-07-27 13:18:57 +02:00
|
|
|
save() {
|
2016-10-18 19:20:51 -07:00
|
|
|
if (isEmpty(this.get('model.general.title'))) {
|
2016-07-28 15:17:14 +02:00
|
|
|
set(this, 'titleError', true);
|
2016-07-27 13:18:57 +02:00
|
|
|
return $("#siteTitle").focus();
|
|
|
|
}
|
|
|
|
|
2016-10-18 19:20:51 -07:00
|
|
|
if (isEmpty(this.get('model.general.message'))) {
|
2016-07-28 15:17:14 +02:00
|
|
|
set(this, 'messageError', true);
|
2016-07-27 13:18:57 +02:00
|
|
|
return $("#siteMessage").focus();
|
|
|
|
}
|
|
|
|
|
2017-06-06 19:00:35 -04:00
|
|
|
if (isEmpty(this.get('model.general.conversionEndpoint'))) {
|
|
|
|
set(this, 'conversionEndpointError', true);
|
|
|
|
return $("#conversionEndpoint").focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
let e = this.get('model.general.conversionEndpoint');
|
2019-03-03 13:10:04 +00:00
|
|
|
if (_.endsWith(e, '/')) {
|
2017-06-06 19:00:35 -04:00
|
|
|
this.set('model.general.conversionEndpoint', e.substring(0, e.length-1));
|
|
|
|
}
|
|
|
|
|
2018-07-05 12:02:10 -04:00
|
|
|
this.set('model.general.maxTags', this.get('maxTags'));
|
2017-06-06 19:00:35 -04:00
|
|
|
|
2019-02-27 13:49:59 +00:00
|
|
|
let domainChanged = this.get('model.general.domain') !== this.get('domain').toLowerCase();
|
|
|
|
this.set('model.general.domain', this.get('domain').toLowerCase());
|
|
|
|
|
2019-01-06 13:50:12 +00:00
|
|
|
this.get('onUpdate')().then(() => {
|
2018-12-05 13:44:10 +00:00
|
|
|
this.notifySuccess('Saved');
|
2016-07-28 15:17:14 +02:00
|
|
|
set(this, 'titleError', false);
|
|
|
|
set(this, 'messageError', false);
|
2017-06-06 19:00:35 -04:00
|
|
|
set(this, 'conversionEndpointError', false);
|
2019-02-27 13:49:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (domainChanged) {
|
|
|
|
let router = this.get('router');
|
|
|
|
router.transitionTo('auth.login');
|
|
|
|
}
|
2016-07-28 15:17:14 +02:00
|
|
|
});
|
2018-11-24 18:39:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onThemeChange(theme) {
|
|
|
|
this.get('appMeta').setTheme(theme);
|
|
|
|
this.set('model.general.theme', theme);
|
2019-01-06 13:50:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onDefaultLogo() {
|
|
|
|
this.get('onDefaultLogo')(this.get('appMeta.orgId'));
|
|
|
|
this.notifySuccess('Using default logo');
|
2016-07-27 13:18:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|