Backbone
If you create complex one-page application, you can use known JavaScript framework Backbone.
The application ToDo was created as an example of using this framework
public/js/app/bb-todo/. To work with this example is possible through the menu
Testing/Todo/backbone, if you login into the application as Admin.
This application manages a list of tasks:
- Add a task
- Save the task to a local or server data store
- Edit the name of the task
- Set a sign that the task was completed
- Delete a task from the list
- Clear all completed tasks
Configuration
Configuring applications ToDo takes place in the file app/Views/Controller/todo/index.html.twig.
Here we add the service Todo and its parameters.
...
<script type="text/javascript">
BSA.ScriptResources.push('Todo');
addScriptParams('Todo',
{
storage: 'server',// local || server
serverStorage: {
urlRoot: '/tasks',
emulateHTTP: true
}
});
</script>
...
If the storage parameter is equal to the value server, the operations tasks
executed on the server storage. Ajax client requests are processed
via controller TodoController app/Controllers/TodoController.php.
The parameters for working with storage server installed in a variable serverStorage.
If the storage parameter is equal to the value local, the operations tasks
executed on the local storage.
The local store is organized with the help of Backbone localStorage Adapter
public/js/lib/backbone/backbone.localStorage.js