From e3ec1fb7efb12c3669855b6c388f196c268680ee Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Mon, 11 Apr 2011 20:22:38 -0500 Subject: Entitlement registration. The entitlement facet will show buttons according to the entitlement status. If it's unregistered, the facet will show a Register button. If it's registered, the facet will show a Consume button. --- install/ui/dialog.js | 3 + install/ui/entitle.js | 211 ++++++++--- install/ui/entity.js | 16 +- install/ui/ipa.css | 4 + install/ui/ipa.js | 15 +- install/ui/test/data/entitle_get_unregistered.json | 11 + install/ui/test/data/entitle_register.json | 26 ++ install/ui/test/data/ipa_init.json | 401 +++++++++++++++++++++ install/ui/widget.js | 3 +- 9 files changed, 638 insertions(+), 52 deletions(-) create mode 100644 install/ui/test/data/entitle_get_unregistered.json create mode 100644 install/ui/test/data/entitle_register.json (limited to 'install/ui') diff --git a/install/ui/dialog.js b/install/ui/dialog.js index 964d5f5f..08fba458 100644 --- a/install/ui/dialog.js +++ b/install/ui/dialog.js @@ -105,6 +105,9 @@ IPA.dialog = function(spec) { }; that.init = function() { + + that.entity = IPA.get_entity(that.entity_name); + for (var i=0; i', { + type: 'button', + name: 'register', + value: 'Register' + }).appendTo(buttons); + $('', { type: 'button', name: 'consume', @@ -108,15 +197,29 @@ IPA.entitle.search_facet = function(spec) { var action_panel = that.get_action_panel(); - var button = $('input[name=consume]', action_panel); + var button = $('input[name=register]', action_panel); + that.register_button = IPA.action_button({ + label: 'Register', + icon: 'ui-icon-plus', + click: function() { + var dialog = that.entity.get_dialog('register'); + dialog.open(that.container); + } + }); + that.register_button.css('display', 'none'); + button.replaceWith(that.register_button); + + button = $('input[name=consume]', action_panel); that.consume_button = IPA.action_button({ label: 'Consume', icon: 'ui-icon-plus', + style: 'display: none;', click: function() { - var dialog = that.get_dialog('consume'); + var dialog = that.entity.get_dialog('consume'); dialog.open(that.container); } }); + that.consume_button.css('display', 'none'); button.replaceWith(that.consume_button); }; @@ -124,6 +227,9 @@ IPA.entitle.search_facet = function(spec) { function on_success(data, text_status, xhr) { + that.register_button.css('display', 'none'); + that.consume_button.css('display', 'inline'); + that.table.empty(); var result = data.result.result; @@ -132,7 +238,7 @@ IPA.entitle.search_facet = function(spec) { that.table.add_record(record); } - var summary = $('span[name=summary]', that.table.tfoot); + var summary = $('span[name=summary]', that.table.tfoot).empty(); if (data.result.truncated) { var message = IPA.messages.search.truncated; message = message.replace('${counter}', data.result.count); @@ -143,28 +249,50 @@ IPA.entitle.search_facet = function(spec) { } function on_error(xhr, text_status, error_thrown) { + + that.register_button.css('display', 'inline'); + that.consume_button.css('display', 'none'); + var summary = $('span[name=summary]', that.table.tfoot).empty(); - summary.append('

Error: '+error_thrown.name+'

'); - summary.append('

'+error_thrown.title+'

'); - summary.append('

'+error_thrown.message+'

'); + summary.append(error_thrown.message); } - var command = IPA.command({ - entity: 'entitle', - method: 'get', - options: { - all: that.search_all - }, - on_success: on_success, - on_error: on_error - }); - - command.execute(); + that.entity.get_certificates( + on_success, + on_error); }; return that; }; +IPA.entitle.register_dialog = function(spec) { + + spec = spec || {}; + + var that = IPA.dialog(spec); + + that.add_button('Register', function() { + var record = {}; + that.save(record); + + that.entity.register( + record.username, + record.password, + function() { + var facet = that.entity.get_facet('search'); + facet.refresh(); + that.close(); + } + ); + }); + + that.add_button('Cancel', function() { + that.close(); + }); + + return that; +}; + IPA.entitle.consume_dialog = function(spec) { spec = spec || {}; @@ -175,19 +303,14 @@ IPA.entitle.consume_dialog = function(spec) { var record = {}; that.save(record); - var command = IPA.command({ - entity: 'entitle', - method: 'consume', - args: [ record.quantity ], - on_success: function() { - var entity = IPA.get_entity(that.entity_name); - var facet = entity.get_facet('search'); - facet.table.refresh(); + that.entity.consume( + record.quantity, + function() { + var facet = that.entity.get_facet('search'); + facet.refresh(); that.close(); } - }); - - command.execute(); + ); }); that.add_button('Cancel', function() { diff --git a/install/ui/entity.js b/install/ui/entity.js index 4db58465..23f792d1 100644 --- a/install/ui/entity.js +++ b/install/ui/entity.js @@ -64,6 +64,9 @@ IPA.facet = function (spec) { }; function init() { + + that.entity = IPA.get_entity(that.entity_name); + for (var i=0; i", + "exclude": null, + "flags": [], + "hint": null, + "include": null, + "label": "", + "length": null, + "maxlength": null, + "minlength": null, + "multivalue": true, + "name": "usercertificate", + "pattern": null, + "pattern_errmsg": null, + "primary_key": false, + "query": false, + "required": false, + "stdin_if_missing": false, + "type": "unicode" + } + ], + "takes_options": [ + { + "alwaysask": false, + "attribute": false, + "autofill": false, + "class": "Str", + "cli_name": "addattr", + "cli_short_name": null, + "default": null, + "doc": "Add an attribute/value pair. Format is attr=value. The attribute must be part of the schema.", + "exclude": [ + "webui" + ], + "flags": [], + "hint": null, + "include": null, + "label": "", + "length": null, + "maxlength": null, + "minlength": null, + "multivalue": true, + "name": "addattr", + "pattern": null, + "pattern_errmsg": null, + "primary_key": false, + "query": false, + "required": false, + "type": "unicode" + }, + { + "alwaysask": false, + "attribute": false, + "autofill": false, + "class": "Str", + "cli_name": "setattr", + "cli_short_name": null, + "default": null, + "doc": "Set an attribute to a name/value pair. Format is attr=value.\nFor multi-valued attributes, the command replaces the values already present.", + "exclude": [ + "webui" + ], + "flags": [], + "hint": null, + "include": null, + "label": "", + "length": null, + "maxlength": null, + "minlength": null, + "multivalue": true, + "name": "setattr", + "pattern": null, + "pattern_errmsg": null, + "primary_key": false, + "query": false, + "required": false, + "type": "unicode" + }, + { + "alwaysask": false, + "attribute": false, + "autofill": true, + "class": "Str", + "cli_name": "uuid", + "cli_short_name": null, + "default": "IMPORTED", + "doc": "Enrollment UUID", + "exclude": null, + "flags": [ + "no_update", + "no_create" + ], + "hint": null, + "include": null, + "label": "UUID", + "length": null, + "maxlength": null, + "minlength": null, + "multivalue": false, + "name": "uuid", + "pattern": null, + "pattern_errmsg": null, + "primary_key": false, + "query": false, + "required": false, + "type": "unicode" + } + ] + }, + "entitle_register": { + "takes_args": [ + { + "alwaysask": false, + "attribute": false, + "autofill": false, + "class": "Str", + "cli_name": "username", + "cli_short_name": null, + "default": null, + "doc": "Username", + "exclude": null, + "flags": [], + "hint": null, + "include": null, + "label": "Username", + "length": null, + "maxlength": null, + "minlength": null, + "multivalue": false, + "name": "username", + "pattern": null, + "pattern_errmsg": null, + "primary_key": false, + "query": false, + "required": true, + "type": "unicode" + } + ], + "takes_options": [ + { + "alwaysask": false, + "attribute": false, + "autofill": false, + "class": "Str", + "cli_name": "addattr", + "cli_short_name": null, + "default": null, + "doc": "Add an attribute/value pair. Format is attr=value. The attribute must be part of the schema.", + "exclude": [ + "webui" + ], + "flags": [], + "hint": null, + "include": null, + "label": "", + "length": null, + "maxlength": null, + "minlength": null, + "multivalue": true, + "name": "addattr", + "pattern": null, + "pattern_errmsg": null, + "primary_key": false, + "query": false, + "required": false, + "type": "unicode" + }, + { + "alwaysask": false, + "attribute": false, + "autofill": false, + "class": "Str", + "cli_name": "setattr", + "cli_short_name": null, + "default": null, + "doc": "Set an attribute to a name/value pair. Format is attr=value.\nFor multi-valued attributes, the command replaces the values already present.", + "exclude": [ + "webui" + ], + "flags": [], + "hint": null, + "include": null, + "label": "", + "length": null, + "maxlength": null, + "minlength": null, + "multivalue": true, + "name": "setattr", + "pattern": null, + "pattern_errmsg": null, + "primary_key": false, + "query": false, + "required": false, + "type": "unicode" + }, + { + "alwaysask": false, + "attribute": false, + "autofill": false, + "class": "Str", + "cli_name": "ipaentitlementid", + "cli_short_name": null, + "default": null, + "doc": "Enrollment UUID", + "exclude": null, + "flags": [ + "no_update", + "no_create" + ], + "hint": null, + "include": null, + "label": "UUID", + "length": null, + "maxlength": null, + "minlength": null, + "multivalue": false, + "name": "ipaentitlementid", + "pattern": null, + "pattern_errmsg": null, + "primary_key": false, + "query": false, + "required": false, + "type": "unicode" + }, + { + "alwaysask": false, + "attribute": false, + "autofill": false, + "class": "Password", + "cli_name": "password", + "cli_short_name": null, + "default": null, + "doc": "Registration password", + "exclude": null, + "flags": [], + "hint": null, + "include": null, + "label": "Password", + "length": null, + "maxlength": null, + "minlength": null, + "multivalue": false, + "name": "password", + "pattern": null, + "pattern_errmsg": null, + "primary_key": false, + "query": false, + "required": true, + "type": "unicode" + } + ] + }, + "entitle_sync": { + "takes_args": [], + "takes_options": [ + { + "alwaysask": false, + "attribute": false, + "autofill": true, + "class": "Int", + "cli_name": "hidden", + "cli_short_name": null, + "default": 1, + "doc": "Quantity", + "exclude": null, + "flags": [ + "no_option", + "no_output" + ], + "hint": null, + "include": null, + "label": "Quantity", + "maxvalue": 2147483647, + "minvalue": 1, + "multivalue": false, + "name": "hidden", + "primary_key": false, + "query": false, + "required": true, + "type": "int" + } + ] + }, "group_add": { "takes_options": [ { diff --git a/install/ui/widget.js b/install/ui/widget.js index fa102737..744e6ed4 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -282,6 +282,7 @@ IPA.text_widget = function(spec) { var that = IPA.widget(spec); that.size = spec.size || 30; + that.type = spec.type || 'text'; that.create = function(container) { @@ -291,7 +292,7 @@ IPA.text_widget = function(spec) { }).appendTo(container); $('', { - type: 'text', + type: that.type, name: that.name, disabled: that.disabled, size: that.size, -- cgit