Lungo.View.Template.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Lungo Template system
  3. *
  4. * @namespace LUNGO.View
  5. * @class Template
  6. *
  7. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  8. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  9. */
  10. LUNGO.View.Template = (function(lng, undefined) {
  11. var _templates = {};
  12. /**
  13. * Create a new databinding template based on a <markup>
  14. *
  15. * @method create
  16. *
  17. * @param {String} Id of the new databinding template
  18. * @param {String} <markup> of the new databinding template
  19. */
  20. var create = function(id, markup) {
  21. _templates[id] = markup;
  22. };
  23. /**
  24. * Returns the existence of a certain Id databinding template
  25. *
  26. * @method exists
  27. *
  28. * @param {String} Id of the databinding template
  29. * @return {Boolean} true if exists, false if not.
  30. */
  31. var exists = function(id) {
  32. return (_templates[id]) ? true : false;
  33. };
  34. /**
  35. * Returns the instance of a certain Id databinding template
  36. *
  37. * @method get
  38. *
  39. * @param {String} Id of the databinding template
  40. * @return {String} Markup of template
  41. */
  42. var get = function(id) {
  43. return _templates[id];
  44. };
  45. /**
  46. * Performs databinding process for a data set and a given template
  47. *
  48. * @method binding
  49. *
  50. * @param {String} Id of the container showing the result of databinding
  51. * @param {String} Databinding Template Id
  52. * @param {Object} Data for binding
  53. * @param {Function} Callback when the process is complete
  54. */
  55. var binding = function(container_id, template_id, data, callback) {
  56. lng.View.Template.Binding.create(container_id, template_id, data, callback);
  57. };
  58. return {
  59. create: create,
  60. exists: exists,
  61. get: get,
  62. binding: binding
  63. };
  64. })(LUNGO);