editor: metadata editor - suggested values for metadata keys
[fnpeditor.git] / src / editor / modules / nodePane / metaWidget / metaWidget.js
1 define([
2 'libs/jquery',
3 'libs/underscore',
4 'libs/backbone',
5 'libs/text!./stringField.html'
6 ], function($, _, Backbone, stringFieldTpl) {
7
8 'use strict';
9
10 var templates = {
11     string: _.template(stringFieldTpl)
12 };
13
14 var getAttrElement = function(attrName, attr) {
15     var toret = $('<div>');
16     toret.append(templates.string({name: attrName, value: attr.value}));
17     return toret;
18 };
19
20 var MetaWidget = Backbone.View.extend({
21     events: {
22         'change [metaField-name]': 'onMetaFieldChange'
23     },
24     initialize: function() {
25         var view = this;
26         _.keys(this.options.attrs).forEach(function(attrName) {
27             view.$el.append(getAttrElement(attrName, this.options.attrs[attrName]));
28         }.bind(this));
29     },
30     onMetaFieldChange: function(e) {
31         var target = $(e.target);
32         this.trigger('valueChanged', target.attr('metaField-name'), target.val());
33     }
34 });
35
36
37 return {
38     create: function(options) {
39         return new MetaWidget(options);
40     }
41 };
42
43 });