Left: | ||
Right: |
OLD | NEW |
---|---|
1 | |
2 | |
3 /* | 1 /* |
4 This file is part of the Juju GUI, which lets users view and manage Juju | 2 This file is part of the Juju GUI, which lets users view and manage Juju |
5 environments within a graphical interface (https://launchpad.net/juju-gui). | 3 environments within a graphical interface (https://launchpad.net/juju-gui). |
6 Copyright (C) 2012-2013 Canonical Ltd. | 4 Copyright (C) 2012-2013 Canonical Ltd. |
7 | 5 |
8 This program is free software: you can redistribute it and/or modify it under | 6 This program is free software: you can redistribute it and/or modify it under |
9 the terms of the GNU Affero General Public License version 3, as published by | 7 the terms of the GNU Affero General Public License version 3, as published by |
10 the Free Software Foundation. | 8 the Free Software Foundation. |
11 | 9 |
12 This program is distributed in the hope that it will be useful, but WITHOUT | 10 This program is distributed in the hope that it will be useful, but WITHOUT |
(...skipping 13 matching lines...) Expand all Loading... | |
26 views = Y.namespace('juju.views'), | 24 views = Y.namespace('juju.views'), |
27 templates = Y.namespace('juju.views').Templates, | 25 templates = Y.namespace('juju.views').Templates, |
28 plugins = Y.namespace('juju.plugins'), | 26 plugins = Y.namespace('juju.plugins'), |
29 models = Y.namespace('juju.models'), | 27 models = Y.namespace('juju.models'), |
30 utils = Y.namespace('juju.views.utils'); | 28 utils = Y.namespace('juju.views.utils'); |
31 | 29 |
32 | 30 |
33 ns.config = { | 31 ns.config = { |
34 name: 'config', | 32 name: 'config', |
35 template: templates['service-configuration'], | 33 template: templates['service-configuration'], |
36 'render': function(service, viewContainerAttrs) { | 34 bindings: { |
rharding
2013/09/11 14:24:17
moved bindings up to the top so it's consistent wi
| |
35 exposed: { | |
36 'update': function(node, val) { | |
rharding
2013/09/11 14:24:17
since the data-bound element is the div, we need t
| |
37 // On exposed, the node is the container of the input we want to | |
38 // change. | |
39 var input = node.one('input'); | |
40 if (input) { | |
41 input.set('checked', val); | |
42 } | |
43 } | |
44 }, | |
45 config: { | |
46 // On update make sure undefined isn't sent to the user as viewable | |
47 // input. | |
48 'update': function(node, val) { | |
49 if (node.getAttribute('type') === 'checkbox') { | |
50 if (val !== node.get('checked')) { | |
51 node.set('checked', val); | |
52 // We cannot simulate a change event here to trigger the textual | |
53 // value to update or else we'll cause databinding to think | |
54 // there's a conflict the next time this is changed via anyone | |
55 // else. | |
56 // We manually set the html content in order to avoid this. | |
57 node.ancestor('.toggle').one('.textvalue').set('text', | |
58 val); | |
59 } | |
60 } else { | |
61 if (val === undefined) { | |
62 val = ''; | |
63 } | |
64 node.set('value', val); | |
65 } | |
66 } | |
67 } | |
68 }, | |
69 /** | |
70 * Bind DOM related events to keep checkboxes in sync with their textual | |
71 * reprensetation. | |
72 * | |
73 * @method _bindDOMEvents | |
74 * | |
75 */ | |
76 _bindDOMEvents: function() { | |
77 // Keep the textual representation of the checkbox in sync with the | |
78 // input node. | |
79 this.events.push( | |
80 this.container.delegate('change', function(ev) { | |
81 var checked = ev.currentTarget.get('checked'); | |
82 ev.target.ancestor('.toggle').one('.textvalue').set('text', | |
83 checked); | |
84 | |
85 }, '.hidden-checkbox') | |
86 ); | |
87 }, | |
88 /** | |
89 * Viewlet standard render call. | |
90 * | |
91 * @method rener | |
92 * @param {Service} service the model of the service in the inspector. | |
93 * @param {Object} viewContainerAttrs an object of helper data from the | |
94 * viewlet manager. | |
95 * | |
96 */ | |
97 render: function(service, viewContainerAttrs) { | |
37 var settings = []; | 98 var settings = []; |
38 var db = viewContainerAttrs.db; | 99 var db = viewContainerAttrs.db; |
39 var charm = db.charms.getById(service.get('charm')); | 100 var charm = db.charms.getById(service.get('charm')); |
40 var templatedSettings = utils.extractServiceSettings( | 101 var templatedSettings = utils.extractServiceSettings( |
41 charm.get('options')); | 102 charm.get('options'), service.get('config')); |
rharding
2013/09/11 14:24:17
In order to sync the values correctly we need to t
| |
42 | 103 |
43 this.container = Y.Node.create(this.templateWrapper); | 104 this.container = Y.Node.create(this.templateWrapper); |
44 | 105 |
45 this.container.setHTML( | 106 this.container.setHTML( |
46 this.template({ | 107 this.template({ |
47 service: service, | 108 service: service, |
48 settings: templatedSettings, | 109 settings: templatedSettings, |
49 exposed: service.get('exposed')})); | 110 exposed: service.get('exposed')})); |
50 this.container.all('textarea.config-field') | 111 this.container.all('textarea.config-field') |
51 .plug(plugins.ResizingTextarea, | 112 .plug(plugins.ResizingTextarea, |
52 { max_height: 200, | 113 { max_height: 200, |
53 min_height: 18, | 114 min_height: 18, |
54 single_line: 18}); | 115 single_line: 18}); |
55 }, | 116 this._bindDOMEvents(); |
56 bindings: { | |
57 exposed: { | |
58 'update': function(node, value) { | |
59 node.one('input').set('checked', value); | |
60 } | |
61 }, | |
62 'config': { | |
63 'update': function(node, val) { | |
64 if (val === undefined) { | |
65 val = ''; | |
66 } | |
67 node.set('value', val); | |
68 } | |
69 } | |
70 } | 117 } |
71 | 118 |
72 }; | 119 }; |
73 }, '0.0.1', { | 120 }, '0.0.1', { |
74 requires: [ | 121 requires: [ |
122 'event-simulate', | |
123 'juju-charm-models', | |
124 'juju-view', | |
75 'node', | 125 'node', |
76 'resizing-textarea', | 126 'resizing-textarea' |
rharding
2013/09/11 14:24:17
:!sort ftw
| |
77 'juju-charm-models', | |
78 'juju-view' | |
79 ] | 127 ] |
80 }); | 128 }); |
OLD | NEW |