'use strict'
Application.Controllers.controller "SettingsController", ["$scope", 'Setting', 'growl', 'settingsPromise', 'cgvFile', 'cguFile', 'logoFile', 'logoBlackFile', 'faviconFile', 'profileImageFile', 'CSRF', '_t'
($scope, Setting, growl, settingsPromise, cgvFile, cguFile, logoFile, logoBlackFile, faviconFile, profileImageFile, CSRF, _t) ->
### PUBLIC SCOPE ###
## timepickers steps configuration
$scope.timepicker =
hstep: 1
mstep: 15
## API URL where the upload forms will be posted
$scope.actionUrl =
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
$scope.methods =
cgu: "post"
cgv: "post"
logo: "post"
logoBlack: "post"
favicon: "post"
profileImage: "post"
## Are we uploading the files currently (if so, display the loader)
$scope.loader =
cgu: false
cgv: false
## 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.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.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
$scope.enableMove =
name: 'booking_move_enable'
value: (settingsPromise.booking_move_enable == "true")
$scope.moveDelay =
name: 'booking_move_delay'
value: parseInt(settingsPromise.booking_move_delay)
$scope.enableCancel =
name: 'booking_cancel_enable'
value: (settingsPromise.booking_cancel_enable == "true")
$scope.cancelDelay =
name: 'booking_cancel_delay'
value: parseInt(settingsPromise.booking_cancel_delay)
$scope.enableReminder =
name: 'reminder_enable'
value: (settingsPromise.reminder_enable == 'true')
$scope.reminderDelay =
name: 'reminder_delay'
value: parseInt(settingsPromise.reminder_delay)
##
# 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)
##
$scope.fileinputClass = (v)->
if v
'fileinput-exists'
else
'fileinput-new'
##
# Callback to save the setting value to the database
# @param setting {{value:*, name:string}} note that the value will be stringified
##
$scope.save = (setting)->
# trim empty html
if setting.value == "
" or setting.value == "