Skip to content
sebez edited this page Nov 19, 2014 · 17 revisions

Chargement des helpers klee

url_helper.js

In the app/lib directory, there is a file url_helper.js, its role is to generate and parse urls calling the methods:

generateUrl

This function is use in order to build url from a rootname and a object you want to pass into the url as params.

var urlHelper = require('../lib/url_helper');
var url = urlHelper.generateUrl('rootName', {param1: "nom", param2: "nom2"}); 
//url = '#rootName/?param1=nom&param2=nom2'

parseUrl

form_helper.js

Allow the user to bind a model backbone to a html form, using data-name attribute. It uses data-* html5 attribute, to match model property.

Backbone model

module.exports = Backbone.Model.extend({
    defaults: {
    	id: undefined,
    	startDate: undefined,
    	endDate: undefined,
    	name: undefined,
    }
});

Html form

This html form comes from a template which is a Handlebars.js template. The View Helper with the input_for method automatically add the data-name attribute to the generated html input. The data-name is use to automatically bind the form on the Backbone model.

<form>
  <input name="inputName" data-name="id"/>
</form>

Usage

Require the helper when you need it:

var formHelper = require('../lib/form_helper');

In the view code, treating the sumbit event or a button event:

//
var data = {
  inputs: $('input', this.$el),
  options: $('option:selected', this.$el)
};
formHelper.formModelBinder(data, this.model);
//The model gets the property id fill by the form.