2018-10-25 16:51:20 +02:00
|
|
|
/* eslint-disable
|
|
|
|
no-return-assign,
|
|
|
|
no-undef,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2018-10-25 16:50:16 +02:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
'use strict'
|
2016-03-23 18:39:41 +01:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
Application.Controllers.controller('SettingsController', ['$scope', 'Setting', 'growl', 'settingsPromise', 'cgvFile', 'cguFile', 'logoFile', 'logoBlackFile', 'faviconFile', 'profileImageFile', 'CSRF', '_t',
|
|
|
|
function ($scope, Setting, growl, settingsPromise, cgvFile, cguFile, logoFile, logoBlackFile, faviconFile, profileImageFile, CSRF, _t) {
|
2018-10-25 16:50:16 +02:00
|
|
|
/* PUBLIC SCOPE */
|
2016-03-23 18:39:41 +01:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
// # timepickers steps configuration
|
2018-10-25 16:50:16 +02:00
|
|
|
$scope.timepicker = {
|
|
|
|
hstep: 1,
|
2016-03-23 18:39:41 +01:00
|
|
|
mstep: 15
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
// # API URL where the upload forms will be posted
|
2018-10-25 16:50:16 +02:00
|
|
|
$scope.actionUrl = {
|
2018-10-25 16:51:20 +02:00
|
|
|
cgu: '/api/custom_assets',
|
|
|
|
cgv: '/api/custom_assets',
|
|
|
|
logo: '/api/custom_assets',
|
|
|
|
logoBlack: '/api/custom_assets',
|
|
|
|
favicon: '/api/custom_assets',
|
|
|
|
profileImage: '/api/custom_assets'
|
|
|
|
}
|
|
|
|
|
|
|
|
// # Form actions on the above URL
|
2018-10-25 16:50:16 +02:00
|
|
|
$scope.methods = {
|
2018-10-25 16:51:20 +02:00
|
|
|
cgu: 'post',
|
|
|
|
cgv: 'post',
|
|
|
|
logo: 'post',
|
|
|
|
logoBlack: 'post',
|
|
|
|
favicon: 'post',
|
|
|
|
profileImage: 'post'
|
|
|
|
}
|
|
|
|
|
|
|
|
// # Are we uploading the files currently (if so, display the loader)
|
2018-10-25 16:50:16 +02:00
|
|
|
$scope.loader = {
|
|
|
|
cgu: false,
|
2016-03-23 18:39:41 +01:00
|
|
|
cgv: false
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// # various parametrable settings
|
|
|
|
$scope.twitterSetting = { name: 'twitter_name', value: settingsPromise.twitter_name }
|
|
|
|
$scope.aboutTitleSetting = { name: 'about_title', value: settingsPromise.about_title }
|
|
|
|
$scope.aboutBodySetting = { name: 'about_body', value: settingsPromise.about_body }
|
|
|
|
$scope.aboutContactsSetting = { name: 'about_contacts', value: settingsPromise.about_contacts }
|
|
|
|
$scope.homeBlogpostSetting = { name: 'home_blogpost', value: settingsPromise.home_blogpost }
|
|
|
|
$scope.machineExplicationsAlert = { name: 'machine_explications_alert', value: settingsPromise.machine_explications_alert }
|
|
|
|
$scope.trainingExplicationsAlert = { name: 'training_explications_alert', value: settingsPromise.training_explications_alert }
|
|
|
|
$scope.trainingInformationMessage = { name: 'training_information_message', value: settingsPromise.training_information_message }
|
|
|
|
$scope.subscriptionExplicationsAlert = { name: 'subscription_explications_alert', value: settingsPromise.subscription_explications_alert }
|
|
|
|
$scope.eventExplicationsAlert = { name: 'event_explications_alert', value: settingsPromise.event_explications_alert }
|
|
|
|
$scope.spaceExplicationsAlert = { name: 'space_explications_alert', value: settingsPromise.space_explications_alert }
|
|
|
|
$scope.windowStart = { name: 'booking_window_start', value: settingsPromise.booking_window_start }
|
|
|
|
$scope.windowEnd = { name: 'booking_window_end', value: settingsPromise.booking_window_end }
|
|
|
|
$scope.mainColorSetting = { name: 'main_color', value: settingsPromise.main_color }
|
|
|
|
$scope.secondColorSetting = { name: 'secondary_color', value: settingsPromise.secondary_color }
|
|
|
|
$scope.fablabName = { name: 'fablab_name', value: settingsPromise.fablab_name }
|
|
|
|
$scope.nameGenre = { name: 'name_genre', value: settingsPromise.name_genre }
|
|
|
|
$scope.machinesSortBy = { name: 'machines_sort_by', value: settingsPromise.machines_sort_by }
|
|
|
|
$scope.cguFile = cguFile.custom_asset
|
|
|
|
$scope.cgvFile = cgvFile.custom_asset
|
|
|
|
$scope.customLogo = logoFile.custom_asset
|
|
|
|
$scope.customLogoBlack = logoBlackFile.custom_asset
|
|
|
|
$scope.customFavicon = faviconFile.custom_asset
|
|
|
|
$scope.profileImage = profileImageFile.custom_asset
|
2018-10-25 16:50:16 +02:00
|
|
|
|
|
|
|
$scope.enableMove = {
|
|
|
|
name: 'booking_move_enable',
|
2018-10-25 16:51:20 +02:00
|
|
|
value: (settingsPromise.booking_move_enable === 'true')
|
|
|
|
}
|
2018-10-25 16:50:16 +02:00
|
|
|
|
|
|
|
$scope.moveDelay = {
|
|
|
|
name: 'booking_move_delay',
|
2017-08-24 18:34:18 +02:00
|
|
|
value: parseInt(settingsPromise.booking_move_delay, 10)
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2016-03-23 18:39:41 +01:00
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
$scope.enableCancel = {
|
|
|
|
name: 'booking_cancel_enable',
|
2018-10-25 16:51:20 +02:00
|
|
|
value: (settingsPromise.booking_cancel_enable === 'true')
|
|
|
|
}
|
2016-03-23 18:39:41 +01:00
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
$scope.cancelDelay = {
|
|
|
|
name: 'booking_cancel_delay',
|
2017-08-24 18:34:18 +02:00
|
|
|
value: parseInt(settingsPromise.booking_cancel_delay, 10)
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2016-11-29 16:46:19 +01:00
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
$scope.enableReminder = {
|
|
|
|
name: 'reminder_enable',
|
|
|
|
value: (settingsPromise.reminder_enable === 'true')
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2016-08-17 12:49:52 +02:00
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
$scope.reminderDelay = {
|
|
|
|
name: 'reminder_delay',
|
2017-08-24 18:34:18 +02:00
|
|
|
value: parseInt(settingsPromise.reminder_delay, 10)
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2017-08-24 18:34:18 +02:00
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
$scope.visibilityYearly = {
|
|
|
|
name: 'visibility_yearly',
|
2017-08-24 18:34:18 +02:00
|
|
|
value: parseInt(settingsPromise.visibility_yearly, 10)
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2017-08-24 18:34:18 +02:00
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
$scope.visibilityOthers = {
|
|
|
|
name: 'visibility_others',
|
2017-08-24 18:34:18 +02:00
|
|
|
value: parseInt(settingsPromise.visibility_others, 10)
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-10-25 16:50:16 +02:00
|
|
|
|
|
|
|
$scope.displayNameEnable = {
|
|
|
|
name: 'display_name_enable',
|
|
|
|
value: (settingsPromise.display_name_enable === 'true')
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
// #
|
2018-10-25 16:50:16 +02:00
|
|
|
// For use with 'ng-class', returns the CSS class name for the uploads previews.
|
|
|
|
// The preview may show a placeholder or the content of the file depending on the upload state.
|
|
|
|
// @param v {*} any attribute, will be tested for truthiness (see JS evaluation rules)
|
2018-10-25 16:51:20 +02:00
|
|
|
// #
|
|
|
|
$scope.fileinputClass = function (v) {
|
2018-10-25 16:50:16 +02:00
|
|
|
if (v) {
|
2018-10-25 16:51:20 +02:00
|
|
|
return 'fileinput-exists'
|
2018-10-25 16:50:16 +02:00
|
|
|
} else {
|
2018-10-25 16:51:20 +02:00
|
|
|
return 'fileinput-new'
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
// #
|
2018-10-25 16:50:16 +02:00
|
|
|
// Callback to save the setting value to the database
|
|
|
|
// @param setting {{value:*, name:string}} note that the value will be stringified
|
2018-10-25 16:51:20 +02:00
|
|
|
// #
|
|
|
|
$scope.save = function (setting) {
|
2018-10-25 16:50:16 +02:00
|
|
|
// trim empty html
|
2018-10-25 16:51:20 +02:00
|
|
|
let value
|
|
|
|
if ((setting.value === '<br>') || (setting.value === '<p><br></p>')) {
|
|
|
|
setting.value = ''
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
// convert dates to ISO format
|
|
|
|
if (setting.value instanceof Date) {
|
2018-10-25 16:51:20 +02:00
|
|
|
setting.value = setting.value.toISOString()
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (setting.value !== null) {
|
2018-10-25 16:51:20 +02:00
|
|
|
value = setting.value.toString()
|
2018-10-25 16:50:16 +02:00
|
|
|
} else {
|
2018-10-25 16:51:20 +02:00
|
|
|
({ value } = setting)
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
return Setting.update({ name: setting.name }, { value }, data => growl.success(_t('settings.customization_of_SETTING_successfully_saved', { SETTING: _t(`settings.${setting.name}`) }))
|
|
|
|
, error => console.log(error))
|
|
|
|
}
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
// #
|
2018-10-25 16:50:16 +02:00
|
|
|
// For use with ngUpload (https://github.com/twilson63/ngUpload).
|
|
|
|
// Intended to be the callback when the upload is done: Any raised error will be displayed in a growl
|
|
|
|
// message. If everything goes fine, a growl success message is shown.
|
|
|
|
// @param content {Object} JSON - The upload's result
|
2018-10-25 16:51:20 +02:00
|
|
|
// #
|
|
|
|
$scope.submited = function (content) {
|
2018-10-25 16:50:16 +02:00
|
|
|
if ((content.custom_asset == null)) {
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.alerts = []
|
|
|
|
return angular.forEach(content, (v, k) =>
|
|
|
|
angular.forEach(v, err => growl.error(err))
|
|
|
|
)
|
2018-10-25 16:50:16 +02:00
|
|
|
} else {
|
2018-10-25 16:51:20 +02:00
|
|
|
growl.success(_t('settings.file_successfully_updated'))
|
2018-10-25 16:50:16 +02:00
|
|
|
if (content.custom_asset.name === 'cgu-file') {
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.cguFile = content.custom_asset
|
|
|
|
$scope.methods.cgu = 'put'
|
|
|
|
if (!($scope.actionUrl.cgu.indexOf('/cgu-file') > 0)) { $scope.actionUrl.cgu += '/cgu-file' }
|
|
|
|
return $scope.loader.cgu = false
|
2018-10-25 16:50:16 +02:00
|
|
|
} else if (content.custom_asset.name === 'cgv-file') {
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.cgvFile = content.custom_asset
|
|
|
|
$scope.methods.cgv = 'put'
|
|
|
|
if (!($scope.actionUrl.cgv.indexOf('/cgv-file') > 0)) { $scope.actionUrl.cgv += '/cgv-file' }
|
|
|
|
return $scope.loader.cgv = false
|
2018-10-25 16:50:16 +02:00
|
|
|
} else if (content.custom_asset.name === 'logo-file') {
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.customLogo = content.custom_asset
|
|
|
|
$scope.methods.logo = 'put'
|
|
|
|
if (!($scope.actionUrl.logo.indexOf('/logo-file') > 0)) { return $scope.actionUrl.logo += '/logo-file' }
|
2018-10-25 16:50:16 +02:00
|
|
|
} else if (content.custom_asset.name === 'logo-black-file') {
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.customLogoBlack = content.custom_asset
|
|
|
|
$scope.methods.logoBlack = 'put'
|
|
|
|
if (!($scope.actionUrl.logoBlack.indexOf('/logo-black-file') > 0)) { return $scope.actionUrl.logoBlack += '/logo-black-file' }
|
2018-10-25 16:50:16 +02:00
|
|
|
} else if (content.custom_asset.name === 'favicon-file') {
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.customFavicon = content.custom_asset
|
|
|
|
$scope.methods.favicon = 'put'
|
|
|
|
if (!($scope.actionUrl.favicon.indexOf('/favicon-file') > 0)) { return $scope.actionUrl.favicon += '/favicon-file' }
|
2018-10-25 16:50:16 +02:00
|
|
|
} else if (content.custom_asset.name === 'profile-image-file') {
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.profileImage = content.custom_asset
|
|
|
|
$scope.methods.profileImage = 'put'
|
|
|
|
if (!($scope.actionUrl.profileImage.indexOf('/profile-image-file') > 0)) { return $scope.actionUrl.profileImage += '/profile-image-file' }
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
// #
|
2018-10-25 16:50:16 +02:00
|
|
|
// @param target {String} 'cgu' | 'cgv'
|
2018-10-25 16:51:20 +02:00
|
|
|
// #
|
|
|
|
$scope.addLoader = target => $scope.loader[target] = true
|
2018-10-25 16:50:16 +02:00
|
|
|
|
|
|
|
/* PRIVATE SCOPE */
|
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
// #
|
2018-10-25 16:50:16 +02:00
|
|
|
// Kind of constructor: these actions will be realized first when the controller is loaded
|
2018-10-25 16:51:20 +02:00
|
|
|
// #
|
|
|
|
const initialize = function () {
|
2018-10-25 16:50:16 +02:00
|
|
|
// set the authenticity tokens in the forms
|
2018-10-25 16:51:20 +02:00
|
|
|
CSRF.setMetaTags()
|
2018-10-25 16:50:16 +02:00
|
|
|
|
|
|
|
// we prevent the admin from setting the closing time before the opening time
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.$watch('windowEnd.value', function (newValue, oldValue, scope) {
|
2018-10-25 16:50:16 +02:00
|
|
|
if ($scope.windowStart && moment($scope.windowStart.value).isAfter(newValue)) {
|
2018-10-25 16:51:20 +02:00
|
|
|
return $scope.windowEnd.value = oldValue
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-10-25 16:51:20 +02:00
|
|
|
})
|
2018-10-25 16:50:16 +02:00
|
|
|
|
|
|
|
// change form methods to PUT if items already exists
|
|
|
|
if (cguFile.custom_asset) {
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.methods.cgu = 'put'
|
|
|
|
$scope.actionUrl.cgu += '/cgu-file'
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
if (cgvFile.custom_asset) {
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.methods.cgv = 'put'
|
|
|
|
$scope.actionUrl.cgv += '/cgv-file'
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
if (logoFile.custom_asset) {
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.methods.logo = 'put'
|
|
|
|
$scope.actionUrl.logo += '/logo-file'
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
if (logoBlackFile.custom_asset) {
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.methods.logoBlack = 'put'
|
|
|
|
$scope.actionUrl.logoBlack += '/logo-black-file'
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
if (faviconFile.custom_asset) {
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.methods.favicon = 'put'
|
|
|
|
$scope.actionUrl.favicon += '/favicon-file'
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
if (profileImageFile.custom_asset) {
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.methods.profileImage = 'put'
|
|
|
|
return $scope.actionUrl.profileImage += '/profile-image-file'
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-10-25 16:50:16 +02:00
|
|
|
|
|
|
|
// init the controller (call at the end !)
|
2018-10-25 16:51:20 +02:00
|
|
|
return initialize()
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
])
|