Skip to content

Methods to get, set, load, and save settings for FCOOs applications

License

Notifications You must be signed in to change notification settings

FCOO/fcoo-settings

Repository files navigation

fcoo-settings

Description

Methods to get, set, load, and save settings for FCOOs applications

Installation

bower

bower install https://github.com/FCOO/fcoo-settings.git --save

Demo

http://FCOO.github.io/fcoo-settings/demo/ (see control panel)

Methods and Usage

In namespace window.fcoo two object are created: fcoo.globalSetting //Contains all global settings (language, date-format etc.) fcoo.appSetting //Contains the setting for the current application

Get and set settings

.add( options )

options = {id, applyFunc, validator, defaultValue, onError )
  • id [String]: The id for the setting
  • applyFunc [Function( value )]: Called when the value of setting id is changed. Used to change elements etc. on the page with the new setting
  • validator (optional): See fcoo/url.js-extensions.
  • defaultValue [any] (optional): Used if no value was found in localStorage
  • callApply [Boolean] (optional) default=true: If true the applyFunc is called when the setting is added
  • globalEvents (optional): Name(s) of events defined in fcoo/fcoo-global-events to be fired when the setting is changed.
  • saveOnChanging [BOOLEAN]. If true the setting is saved during editing. When false the setting is only saved when edit-form submits
  • onError [Function( value, id )] (optional): Called if a new value is invalid according to validator
  • modernizr BOOLEAN (optional) default=false: If true the modernizr-class descriped in src\_fcoo-settings.scss is updated
  • modernizrOnlyValues []ID: List of the only values that are modernizr'ed. If empty all values are modernizr

.set( {ID:VALUE} )

Sets the value for settings ID If value is undefined => use the saved value The applyFunc is called with the new value

.get( id )

Return the current value (any type) of settings for id

.load([id])

Load the setting's data from indexedDB id (optional) Load a different data-set load() is called on loading the page, and normally it would not need to be called again

.save(callback)

Save the settings to indexedDB

.saveAs(id, callback)

Save the settings to indexedDB with a new id

.delete([id], [callback])

Delete the settings with id or default-id from indexedDB

Edit global settings in a modal window

To allow the user to edit the global settings the following methods are defined to retrieve and display the modal. The modal contain an accordion with e card for each of the global events in fcoo/fcoo-global-events The different "Administrator" (see FCOO/fcoo-web-application-settings) will provide the content for each accordion card by calling fcoo.settings.addModalContent(globalEventId, content) The modal is displayed by calling fcoo.globalSetting.edit()

fcoo.globalSetting.addModalContent(globalEventId, content)

Add content to for accordion card with id and content as array of bsOptions (see FCOO/jquery-bootstrap)

fcoo.globalSetting.edit([id])

Create and display the modal-window with edit-fields for the different groups given by the global events If id is given the card with the id is open by default

Copyright and License

This plugin is licensed under the MIT license.

Copyright (c) 2016 FCOO

Contact information

Niels Holt [email protected]

About

Methods to get, set, load, and save settings for FCOOs applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published