The first step is getting our code base connected to your webpage. Fortunately this is easy- just attach our script to your header. Copy and paste the code below into the editor and click "I installed NimbusBase" to validate.
<script src="http://nimbusbase.com/static/nimbus.min.js"></script>
An app key is a string you generate from your access keys from Google and Dropbox to allow your app to call them. For the purposes of the tutorial, we created one for you. Add the following line to your code.
sync_string = { "Dropbox": { "key": "q5yx30gr8mcvq4f", "secret": "qy64qphr70lwui5", "app_name": "taskstrike" }, "synchronous": true };
The code below means that when I click this button, it will ask to authorize with DropBox. Click and authenticate and then move on to the next step.
<a onclick="Nimbus.Auth.authorize('Dropbox')">authorize me</a>
Let’s create a model. I’m going to do one called Task. Models are schemas for data objects we want to store. Add the following:
Tasks = Nimbus.Model.setup("Tasks", ["descrip", "done"]);
Now that the model has been defined in the last step, you can add data of that type:
Tasks.create({"descrip":"New task", "done":false });
When you create a data object, it is automatically stored locally. If you have an internet connection, it also persists the objects in real time to Dropbox as you create them.
You can either find data by its id or find a set of data by a filter criteria.
To find a data by its id, do the following:
instance = Tasks.findByAttribute("done", false);
Just change the attribute you want on the data and call Save().
instance.done = false; instance.save();
Just call destroy on the data variable you want to delete.
instance.destroy();