diff options
author | Pavel Vomacka <pvomacka@redhat.com> | 2016-06-13 10:27:52 +0200 |
---|---|---|
committer | Petr Vobornik <pvoborni@redhat.com> | 2016-06-21 14:15:56 +0200 |
commit | ab52b33c71d62524b9d46a66a22ec0440d23ff38 (patch) | |
tree | 9b69d234a6835f169337de14f4f47f13844e1077 | |
parent | be235cedf88ee69430abea44ad1eca4bc5817d7b (diff) | |
download | freeipa-ab52b33c71d62524b9d46a66a22ec0440d23ff38.tar.gz freeipa-ab52b33c71d62524b9d46a66a22ec0440d23ff38.tar.xz freeipa-ab52b33c71d62524b9d46a66a22ec0440d23ff38.zip |
Add listener which opens add segment dialog
The event is emited by clicking on the second node when adding segment by mouse.
The listener opens dialog and prefill values.
Part of: https://fedorahosted.org/freeipa/ticket/5648
Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
-rw-r--r-- | install/ui/src/freeipa/topology.js | 180 |
1 files changed, 107 insertions, 73 deletions
diff --git a/install/ui/src/freeipa/topology.js b/install/ui/src/freeipa/topology.js index 4cd25ea30..dc214227f 100644 --- a/install/ui/src/freeipa/topology.js +++ b/install/ui/src/freeipa/topology.js @@ -805,6 +805,12 @@ topology.TopologyGraphFacet = declare([Facet, ActionMixin, HeaderMixin], { this.set_selected_link(data.link); }.bind(this)); + on(graph, 'add-agreement', function(link) { + var dialog = topology.create_add_dialog(); + dialog.open(); + dialog.prefill_dialog(link); + }); + on(this, 'hide', function () { $(window).off('resize', null, listener); }); @@ -839,102 +845,129 @@ topology.TopologyGraphFacet = declare([Facet, ActionMixin, HeaderMixin], { } }); + /** - * Shows topology segment adder dialog with suffix select + * Creates segment adder dialog according to spec. * - * @class topology.add_segment_action - * @extends IPA.action + * @param spec {Object} */ -topology.add_segment_action = function(spec) { +topology.create_add_dialog = function(spec) { spec = spec || {}; - spec.name = spec.name || 'segment_add'; - spec.method = spec.method || 'add'; - spec.enable_cond = spec.enable_cond || ['managed-topology']; - var that = IPA.action(spec); + spec.entity = spec.entity || 'topologysegment'; - that.execute_action = function(facet, on_success, on_error) { + var entity = reg.entity.get('topologysegment'); + var title = text.get('@i18n:dialogs.add_title'); + var label = entity.metadata.label_singular; + spec.title = title.replace('${entity}', label); - that.facet = facet; - - var entity = reg.entity.get('topologysegment'); - var title = text.get('@i18n:dialogs.add_title'); - var label = entity.metadata.label_singular; - title = title.replace('${entity}', label); + spec.fields = spec.fields || [ + { + name: 'cn', + required: false + }, + { + $type: 'entity_select', + name: 'suffix', + label: '@mo:topologysuffix.label_singular', + other_entity: 'topologysuffix', + other_field: 'cn', + z_index: 3, + required: true + }, + { + $type: 'entity_select', + name: 'iparepltoposegmentleftnode', + other_entity: 'server', + other_field: 'cn', + z_index: 2 + }, + { + $type: 'entity_select', + name: 'iparepltoposegmentrightnode', + other_entity: 'server', + other_field: 'cn', + z_index: 1 + } + ]; - var dialog = IPA.entity_adder_dialog({ - entity: 'topologysegment', - title: title, - fields: [ - { - name: 'cn', - required: false - }, - { - $type: 'entity_select', - name: 'suffix', - label: '@mo:topologysuffix.label_singular', - other_entity: 'topologysuffix', - other_field: 'cn', - z_index: 3, - required: true - }, - { - $type: 'entity_select', - name: 'iparepltoposegmentleftnode', - other_entity: 'server', - other_field: 'cn', - z_index: 2 - }, - { - $type: 'entity_select', - name: 'iparepltoposegmentrightnode', - other_entity: 'server', - other_field: 'cn', - z_index: 1 - } - ] - }); - dialog.added.attach(that.on_success); - dialog.show_edit_page = function(entity, result) { - var suffix = this.fields.get_field('suffix').save()[0]; - var cn = result.cn[0]; - navigation.show_entity(entity.name, 'default', [suffix, cn]); - }; + var that = IPA.entity_adder_dialog(spec); - dialog.create_add_command = function(record) { + that.init = function() { + that.added.attach(that.on_success); + }; - var args = [this.fields.get_field('suffix').save()[0]]; - var cn = this.fields.get_field('cn').save()[0]; - if (cn) args.push(cn); + that.show_edit_page = function(entity, result) { + var suffix = this.fields.get_field('suffix').save()[0]; + var cn = result.cn[0]; + navigation.show_entity(entity.name, 'default', [suffix, cn]); + }; - var options = { - 'iparepltoposegmentleftnode': - this.fields.get_field('iparepltoposegmentleftnode').save()[0], - 'iparepltoposegmentrightnode': - this.fields.get_field('iparepltoposegmentrightnode').save()[0] - }; + that.create_add_command = function(record) { - var command = rpc.command({ - entity: this.entity.name, - method: this.method, - retry: this.retry, - args: args, - options: options - }); + var args = [this.fields.get_field('suffix').save()[0]]; + var cn = this.fields.get_field('cn').save()[0]; + if (cn) args.push(cn); - return command; + var options = { + 'iparepltoposegmentleftnode': + this.fields.get_field('iparepltoposegmentleftnode').save()[0], + 'iparepltoposegmentrightnode': + this.fields.get_field('iparepltoposegmentrightnode').save()[0] }; - dialog.open(); + var command = rpc.command({ + entity: this.entity.name, + method: this.method, + retry: this.retry, + args: args, + options: options + }); + + return command; }; + that.on_success = function(data) { that.facet.refresh(); }; + that.prefill_dialog = function(link) { + that.get_field('iparepltoposegmentleftnode').set_value([link.source.id]); + that.get_field('iparepltoposegmentrightnode').set_value([link.target.id]); + that.get_field('suffix').set_value([link.suffix]); + }; + + that.init(); + + return that; +}; + +/** + * Shows topology segment adder dialog with suffix select + * + * @class topology.add_segment_action + * @extends IPA.action + */ +topology.add_segment_action = function(spec) { + + spec = spec || {}; + spec.name = spec.name || 'segment_add'; + spec.method = spec.method || 'add'; + spec.enable_cond = spec.enable_cond || ['managed-topology']; + + var that = IPA.action(spec); + + that.execute_action = function(facet, on_success, on_error) { + + var dialog = topology.create_add_dialog(); + + dialog.open(); + }; + + return that; }; @@ -1230,6 +1263,7 @@ topology.TopologyGraphWidget = declare([Stateful, Evented], { } forward('link-selected'); + forward('add-agreement'); }, _update_view: function() { |