From 805b94f22d42eddee42ed8772aca89036edb8399 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Tue, 12 Apr 2011 02:13:30 -0500 Subject: Merged IPA.cmd() into IPA.command(). The IPA.cmd() has been merged into IPA.command(). All invocations and test cases have been converted. Ticket #988 --- install/ui/add.js | 3 +- install/ui/associate.js | 63 +++-- install/ui/certificate.js | 86 ++++--- install/ui/details.js | 9 +- install/ui/dns.js | 16 +- install/ui/entitle.js | 6 +- install/ui/hbac.js | 72 +++--- install/ui/host.js | 28 +-- install/ui/ipa.js | 430 ++++++++++++++++++----------------- install/ui/rule.js | 14 +- install/ui/search.js | 6 +- install/ui/service.js | 11 +- install/ui/sudo.js | 93 ++++---- install/ui/test/association_tests.js | 100 ++++---- install/ui/test/details_tests.js | 18 +- install/ui/test/ipa_tests.js | 22 +- install/ui/user.js | 12 +- install/ui/widget.js | 12 +- 18 files changed, 572 insertions(+), 429 deletions(-) (limited to 'install') diff --git a/install/ui/add.js b/install/ui/add.js index 33ffe3dea..45b49899f 100644 --- a/install/ui/add.js +++ b/install/ui/add.js @@ -97,7 +97,8 @@ IPA.add_dialog = function (spec) { var pkey_name = IPA.metadata.objects[that.entity_name].primary_key; var command = IPA.command({ - method: that.entity_name+'_add', + entity: that.entity_name, + method: 'add', on_success: on_success, on_error: on_error }); diff --git a/install/ui/associate.js b/install/ui/associate.js index b8a7d825a..f4ebb1ef7 100644 --- a/install/ui/associate.js +++ b/install/ui/associate.js @@ -75,7 +75,8 @@ IPA.serial_associator = function(spec) { options[that.entity_name] = that.pkey; var command = IPA.command({ - method: that.other_entity+'_'+that.method, + entity: that.other_entity, + method: that.method, args: args, options: options, on_success: that.execute, @@ -122,7 +123,8 @@ IPA.bulk_associator = function(spec) { options[that.other_entity] = value; var command = IPA.command({ - method: that.entity_name+'_'+that.method, + entity: that.entity_name, + method: that.method, args: args, options: options, on_success: that.on_success, @@ -206,7 +208,13 @@ IPA.association_adder_dialog = function (spec) { } } - IPA.cmd('find', [that.get_filter()], options, on_success, null, that.other_entity); + IPA.command({ + entity: that.other_entity, + method: 'find', + args: [that.get_filter()], + options: options, + on_success: on_success + }).execute(); }; that.association_adder_dialog_init = that.init; @@ -474,11 +482,12 @@ IPA.association_table_widget = function (spec) { var value = that.values[i]; var command = IPA.command({ - 'method': that.other_entity+'_show', - 'args': [value], - 'options': { - 'all': true, - 'rights': true + entity: that.other_entity, + method: 'show', + args: [value], + options: { + all: true, + rights: true } }); @@ -569,10 +578,11 @@ IPA.association_table_widget = function (spec) { var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; var command = IPA.command({ - 'method': that.entity_name+'_'+that.add_method, - 'args': [pkey], - 'on_success': on_success, - 'on_error': on_error + entity: that.entity_name, + method: that.add_method, + args: [pkey], + on_success: on_success, + on_error: on_error }); command.set_option(that.other_entity, values.join(',')); @@ -631,10 +641,11 @@ IPA.association_table_widget = function (spec) { var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; var command = IPA.command({ - 'method': that.entity_name+'_'+that.remove_method, - 'args': [pkey], - 'on_success': on_success, - 'on_error': on_error + entity: that.entity_name, + method: that.remove_method, + args: [pkey], + on_success: on_success, + on_error: on_error }); command.set_option(that.other_entity, values.join(',')); @@ -985,11 +996,12 @@ IPA.association_facet = function (spec) { options[relationship_filter] = pkey; var command = IPA.command({ - 'on_success': on_success, - 'on_error': on_error, - 'method': that.other_entity+'_find', - 'args': args, - options: options + entity: that.other_entity, + method: 'find', + args: args, + options: options, + on_success: on_success, + on_error: on_error }); command.execute(); @@ -1036,7 +1048,14 @@ IPA.association_facet = function (spec) { } var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; - IPA.cmd('show', [pkey], {'all': true, 'rights': true}, on_success, on_error, that.entity_name); + IPA.command({ + entity: that.entity_name, + method: 'show', + args: [pkey], + options: {'all': true, 'rights': true}, + on_success: on_success, + on_error: on_error + }).execute(); }; that.association_facet_init = that.init; diff --git a/install/ui/certificate.js b/install/ui/certificate.js index fea7448cd..c52163629 100755 --- a/install/ui/certificate.js +++ b/install/ui/certificate.js @@ -511,11 +511,14 @@ IPA.cert.status_widget = function(spec) { that.get_button = IPA.button({ label: IPA.messages.buttons.get, 'click': function() { - IPA.cmd(that.entity_name+'_show', [that.pkey], {}, - function(data, text_status, xhr) { + IPA.command({ + entity: that.entity_name, + method: 'show', + args: [that.pkey], + on_success: function(data, text_status, xhr) { get_certificate(data.result.result); } - ); + }).execute(); } }); button.replaceWith(that.get_button); @@ -524,11 +527,14 @@ IPA.cert.status_widget = function(spec) { that.revoke_button = IPA.button({ label: IPA.messages.buttons.revoke, 'click': function() { - IPA.cmd(that.entity_name+'_show', [that.pkey], {}, - function(data, text_status, xhr) { + IPA.command({ + entity: that.entity_name, + method: 'show', + args: [that.pkey], + on_success: function(data, text_status, xhr) { revoke_certificate(data.result.result); } - ); + }).execute(); } }); button.replaceWith(that.revoke_button); @@ -537,11 +543,14 @@ IPA.cert.status_widget = function(spec) { that.view_button = IPA.button({ label: IPA.messages.buttons.view, 'click': function() { - IPA.cmd(that.entity_name+'_show', [that.pkey], {}, - function(data, text_status, xhr) { + IPA.command({ + entity: that.entity_name, + method: 'show', + args: [that.pkey], + on_success: function(data, text_status, xhr) { view_certificate(data.result.result); } - ); + }).execute(); } }); button.replaceWith(that.view_button); @@ -552,11 +561,14 @@ IPA.cert.status_widget = function(spec) { that.restore_button = IPA.button({ label: IPA.messages.buttons.restore, 'click': function() { - IPA.cmd(that.entity_name+'_show', [that.pkey], {}, - function(data, text_status, xhr) { + IPA.command({ + entity: that.entity_name, + method: 'show', + args: [that.pkey], + on_success: function(data, text_status, xhr) { restore_certificate(data.result.result); } - ); + }).execute(); } }); button.replaceWith(that.restore_button); @@ -605,11 +617,11 @@ IPA.cert.status_widget = function(spec) { return; } - IPA.cmd( - 'cert_show', - [serial_number], - { }, - function(data, text_status, xhr) { + IPA.command({ + entity: 'cert', + method: 'show', + args: [serial_number], + on_success: function(data, text_status, xhr) { var revocation_reason = data.result.result.revocation_reason; if (revocation_reason == undefined) { set_status(IPA.cert.CERTIFICATE_STATUS_VALID); @@ -617,7 +629,7 @@ IPA.cert.status_widget = function(spec) { set_status(IPA.cert.CERTIFICATE_STATUS_REVOKED, revocation_reason); } } - ); + }).execute(); } function view_certificate(result) { @@ -686,16 +698,17 @@ IPA.cert.status_widget = function(spec) { 'request': function(values) { var request = values['request']; - IPA.cmd( - 'cert_request', - [request], - { + IPA.command({ + entity: 'cert', + method: 'request', + args: [request], + options: { 'principal': entity_principal }, - function(data, text_status, xhr) { + on_success: function(data, text_status, xhr) { check_status(data.result.result.serial_number); } - ); + }).execute(); } }); @@ -723,16 +736,17 @@ IPA.cert.status_widget = function(spec) { 'revoke': function(values) { var reason = values['reason']; - IPA.cmd( - 'cert_revoke', - [serial_number], - { + IPA.command({ + entity: 'cert', + method: 'revoke', + args: [serial_number], + options: { 'revocation_reason': reason }, - function(data, text_status, xhr) { + on_success: function(data, text_status, xhr) { check_status(serial_number); } - ); + }).execute(); } }); @@ -758,14 +772,14 @@ IPA.cert.status_widget = function(spec) { var dialog = IPA.cert.restore_dialog({ 'title': title, 'restore': function(values) { - IPA.cmd( - 'cert_remove_hold', - [serial_number], - { }, - function(data, text_status, xhr) { + IPA.command({ + entity: 'cert', + method: 'remove_hold', + args: [serial_number], + on_success: function(data, text_status, xhr) { check_status(serial_number); } - ); + }).execute(); } }); diff --git a/install/ui/details.js b/install/ui/details.js index 794e19fd2..0a22c1773 100644 --- a/install/ui/details.js +++ b/install/ui/details.js @@ -572,9 +572,9 @@ IPA.details_refresh = function() { that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) ; var command = IPA.command({ - method: that.entity_name+'_show', - args: [], - options: { 'all': true, 'rights': true } + entity: that.entity_name, + method: 'show', + options: { all: true, rights: true } }); if (IPA.details_refresh_devel_hook){ @@ -671,7 +671,8 @@ IPA.details_update = function(on_win, on_fail) { var args = pkey ? [pkey] : []; var command = IPA.command({ - method: entity_name+'_mod', + entity: entity_name, + method: 'mod', args: args, options: modlist, on_success: on_success, diff --git a/install/ui/dns.js b/install/ui/dns.js index d7175a140..08aac113c 100644 --- a/install/ui/dns.js +++ b/install/ui/dns.js @@ -160,7 +160,8 @@ IPA.records_facet = function (spec){ options[key] = dialog.data.val(); var command = IPA.command({ - method: 'dnsrecord_add', + entity: 'dnsrecord', + method: 'add', args: [pkey, resource], options: options, on_success: function(data, text_status, xhr) { @@ -256,7 +257,8 @@ IPA.records_facet = function (spec){ var record = records[i]; var command = IPA.command({ - method: 'dnsrecord_del', + entity: 'dnsrecord', + method: 'del', args: [zone, record.resource] }); @@ -434,8 +436,14 @@ IPA.records_facet = function (spec){ if (resource_filter){ pkey.push(resource_filter); } - IPA.cmd('dnsrecord_find',pkey,options,load_on_win, load_on_fail); - + IPA.command({ + entity: 'dnsrecord', + method: 'find', + args: pkey, + options: options, + on_success: load_on_win, + on_error:load_on_fail + }).execute(); } diff --git a/install/ui/entitle.js b/install/ui/entitle.js index 3f62860c5..47143347f 100644 --- a/install/ui/entitle.js +++ b/install/ui/entitle.js @@ -150,7 +150,8 @@ IPA.entitle.search_facet = function(spec) { } var command = IPA.command({ - method: 'entitle_get', + entity: 'entitle', + method: 'get', options: { all: that.search_all }, @@ -175,7 +176,8 @@ IPA.entitle.consume_dialog = function(spec) { that.save(record); var command = IPA.command({ - method: 'entitle_consume', + entity: 'entitle', + method: 'consume', args: [ record.quantity ], on_success: function() { var entity = IPA.get_entity(that.entity_name); diff --git a/install/ui/hbac.js b/install/ui/hbac.js index fa824ab82..a0a713405 100644 --- a/install/ui/hbac.js +++ b/install/ui/hbac.js @@ -343,17 +343,19 @@ IPA.hbacrule_details_facet = function (spec) { var modify_operation = { 'execute': false, 'command': IPA.command({ - 'method': that.entity_name+'_mod', - 'args': [pkey], - 'options': {'all': true, 'rights': true} + entity: that.entity_name, + method: 'mod', + args: [pkey], + options: {all: true, rights: true} }) }; var remove_accesstime = { 'template': IPA.command({ - 'method': that.entity_name+'_remove_accesstime', - 'args': [pkey], - 'options': {'all': true, 'rights': true} + entity: that.entity_name, + method: 'remove_accesstime', + args: [pkey], + options: {all: true, rights: true} }), 'commands': [] }; @@ -378,36 +380,40 @@ IPA.hbacrule_details_facet = function (spec) { 'category': 'usercategory', 'has_values': false, 'command': IPA.command({ - 'method': that.entity_name+'_remove_user', - 'args': [pkey], - 'options': {'all': true, 'rights': true} + entity: that.entity_name, + method: 'remove_user', + args: [pkey], + options: {all: true, rights: true} }) }, 'memberhost': { 'category': 'hostcategory', 'has_values': false, 'command': IPA.command({ - 'method': that.entity_name+'_remove_host', - 'args': [pkey], - 'options': {'all': true, 'rights': true} + entity: that.entity_name, + method: 'remove_host', + args: [pkey], + options: {all: true, rights: true} }) }, 'memberservice': { 'category': 'servicecategory', 'has_values': false, 'command': IPA.command({ - 'method': that.entity_name+'_remove_service', - 'args': [pkey], - 'options': {'all': true, 'rights': true} + entity: that.entity_name, + method: 'remove_service', + args: [pkey], + options: {all: true, rights: true} }) }, 'sourcehost': { 'category': 'sourcehostcategory', 'has_values': false, 'command': IPA.command({ - 'method': that.entity_name+'_remove_sourcehost', - 'args': [pkey], - 'options': {'all': true, 'rights': true} + entity: that.entity_name, + method: 'remove_sourcehost', + args: [pkey], + options: {all: true, rights: true} }) } }; @@ -415,9 +421,10 @@ IPA.hbacrule_details_facet = function (spec) { var enable_operation = { 'execute': false, 'command': IPA.command({ - 'method': that.entity_name+'_enable', - 'args': [pkey], - 'options': {'all': true, 'rights': true} + entity: that.entity_name, + method: 'enable', + args: [pkey], + options: {all: true, rights: true} }) }; @@ -883,13 +890,14 @@ IPA.hbacrule_accesstime_widget = function (spec) { var value = field.save()[0]; var command = IPA.command({ - 'method': that.entity_name+'_add_'+that.name, - 'args': [pkey], - 'on_success': function() { + entity: that.entity_name, + method: 'add_'+that.name, + args: [pkey], + on_success: function() { that.refresh(); if (on_success) on_success(); }, - 'on_error': function() { + on_error: function() { that.refresh(); if (on_error) on_error(); } @@ -960,8 +968,9 @@ IPA.hbacrule_accesstime_widget = function (spec) { for (var i=0; i', { + id: 'error_dialog' + }); + + if (error_thrown.url) { + $('

', { + text: 'URL: '+error_thrown.url + }).appendTo(IPA.error_dialog); + } + + $('

', { + html: error_thrown.message + }).appendTo(IPA.error_dialog); + + function close() { + IPA.error_dialog.dialog('destroy'); + IPA.error_dialog.remove(); + IPA.error_dialog = null; + } + + var buttons = {}; + + /** + * When a user initially opens the Web UI without a Kerberos + * ticket, the messages including the button labels have not + * been loaded yet, so the button labels need default values. + */ + var label = IPA.messages.buttons ? IPA.messages.buttons.retry : 'Retry'; + buttons[label] = function() { + close(); + that.execute(); + }; + + label = IPA.messages.buttons ? IPA.messages.buttons.cancel : 'Cancel'; + buttons[label] = function() { + close(); + if (that.on_error) { + that.on_error.call(this, xhr, text_status, error_thrown); + } + }; + + IPA.error_dialog.dialog({ + modal: true, + title: error_thrown.title, + width: 400, + buttons: buttons, + close: function() { + close(); + } + }); + } + + function error_handler(xhr, text_status, error_thrown) { + + IPA.hide_activity_icon(); + + if (!error_thrown) { + error_thrown = { + name: xhr.responseText || 'Unknown Error', + message: xhr.statusText || 'Unknown Error' + }; + } + + if (xhr.status === 401) { + error_thrown.name = 'Kerberos ticket no longer valid.'; + if (IPA.messages && IPA.messages.ajax) { + error_thrown.message = IPA.messages.ajax["401"]; + } else { + error_thrown.message = + "Your kerberos ticket is no longer valid. "+ + "Please run kinit and then click 'Retry'. "+ + "If this is your first time running the IPA Web UI "+ + ""+ + "follow these directions to configure your browser."; + } + } + + if (!error_thrown.title) { + error_thrown.title = 'AJAX Error: '+error_thrown.name; + } + dialog_open.call(this, xhr, text_status, error_thrown); + } + + function success_handler(data, text_status, xhr) { + + IPA.hide_activity_icon(); + + if (!data) { + var error_thrown = { + title: 'HTTP Error '+xhr.status, + url: this.url, + message: data ? xhr.statusText : "No response" + }; + dialog_open.call(this, xhr, text_status, error_thrown); + + } else if (data.error) { + error_handler.call(this, xhr, text_status, /* error_thrown */ { + title: 'IPA Error '+data.error.code, + message: data.error.message + }); + + } else if (that.on_success) { + that.on_success.call(this, data, text_status, xhr); + } + } + + var url = IPA.json_url; + + var command = that.get_command(); + + if (IPA.use_static_files) { + url += '/' + (that.name ? that.name : command) + '.json'; + } + + var data = { + method: command, + params: [that.args, that.options] + }; + + var request = { + url: url, + data: JSON.stringify(data), + success: success_handler, + error: error_handler + }; + + IPA.display_activity_icon(); + $.ajax(request); }; that.to_json = function() { var json = {}; - json.method = that.method; + json.method = that.get_command(); json.params = []; json.params[0] = that.args || []; @@ -238,7 +415,7 @@ IPA.command = function(spec) { }; that.to_string = function() { - var string = that.method.replace(/_/g, '-'); + var string = that.get_command().replace(/_/g, '-'); for (var i=0; i', { - id: 'error_dialog' - }); - - if (error_thrown.url) { - $('

', { - text: 'URL: '+error_thrown.url - }).appendTo(IPA.error_dialog); - } - $('

', { - html: error_thrown.message - }).appendTo(IPA.error_dialog); - - function close() { - IPA.error_dialog.dialog('destroy'); - IPA.error_dialog.remove(); - IPA.error_dialog = null; - } - - var buttons = {}; - - /** - * When a user initially opens the Web UI without a Kerberos - * ticket, the messages including the button labels have not - * been loaded yet, so the button labels need default values. - */ - var label = IPA.messages.buttons ? IPA.messages.buttons.retry : 'Retry'; - buttons[label] = function() { - close(); - IPA.cmd(name, args, options, win_callback, fail_callback, - objname, command_name); - }; - - label = IPA.messages.buttons ? IPA.messages.buttons.cancel : 'Cancel'; - buttons[label] = function() { - close(); - if (fail_callback) { - fail_callback.call(that, xhr, text_status, error_thrown); } - }; - - IPA.error_dialog.dialog({ - modal: true, - title: error_thrown.title, - width: 400, - buttons: buttons, - close: function() { - close(); - } - }); - } - - function error_handler(xhr, text_status, error_thrown) { - hide_activity_icon(); - if (!error_thrown) { - error_thrown = { - name: xhr.responseText || 'Unknown Error', - message: xhr.statusText || 'Unknown Error' - }; - } - - if (xhr.status === 401) { - error_thrown.name = 'Kerberos ticket no longer valid.'; - if (IPA.messages && IPA.messages.ajax){ - error_thrown.message = IPA.messages.ajax["401"]; - } else { - error_thrown.message = - "Your kerberos ticket is no longer valid. "+ - "Please run kinit and then click 'Retry'. "+ - "If this is your first time running the IPA Web UI "+ - ""+ - "follow these directions to configure your browser."; - } - } - - if (!error_thrown.title) { - error_thrown.title = 'AJAX Error: '+error_thrown.name; - } - dialog_open.call(this, xhr, text_status, error_thrown); - } - - function success_handler(data, text_status, xhr) { - hide_activity_icon(); - if (!data) { - var error_thrown = { - title: 'HTTP Error '+xhr.status, - url: this.url, - message: data ? xhr.statusText : "No response" - }; - dialog_open.call(this, xhr, text_status, error_thrown); - - } else if (data.error) { - error_handler.call(this, xhr, text_status, /* error_thrown */ { - title: 'IPA Error '+data.error.code, - message: data.error.message - }); - - } else if (win_callback) { - win_callback.call(this, data, text_status, xhr); - } - } - - IPA.jsonrpc_id += 1; - var id = IPA.jsonrpc_id; - - var method_name = name; - - if (objname){ - method_name = objname + '_' + name; - } - - var url = IPA.json_url; - - if (IPA.use_static_files){ - if (command_name) { - url += '/' + command_name + '.json'; - } else { - url += '/' + method_name + '.json'; - } - } - var data = { - method: method_name, - params: [args, options], - id: id + }).execute(); }; - var request = { - url: url, - data: JSON.stringify(data), - success: success_handler, - error: error_handler - }; - display_activity_icon(); - $.ajax(request); - - return (id); + return that; }; - /* helper function used to retrieve information about an attribute */ IPA.get_entity_param = function(entity_name, name) { diff --git a/install/ui/rule.js b/install/ui/rule.js index 9076f4ee4..8c69eca8b 100644 --- a/install/ui/rule.js +++ b/install/ui/rule.js @@ -145,10 +145,11 @@ IPA.rule_association_table_widget = function (spec) { if (that.category) { command = IPA.command({ - 'method': that.entity_name+'_mod', - 'args': [pkey], - 'options': {'all': true, 'rights': true}, - 'on_success': function() { + entity: that.entity_name, + method: 'mod', + args: [pkey], + options: {all: true, rights: true}, + on_success: function() { var record = {}; record[that.category.name] = ['']; that.category.load(record); @@ -159,8 +160,9 @@ IPA.rule_association_table_widget = function (spec) { } command = IPA.command({ - 'method': that.entity_name+'_'+that.add_method, - 'args': [pkey] + entity: that.entity_name, + method: that.add_method, + args: [pkey] }); command.set_option(that.other_entity, values.join(',')); batch.add_command(command); diff --git a/install/ui/search.js b/install/ui/search.js index 91ef5bde8..f2789f62e 100644 --- a/install/ui/search.js +++ b/install/ui/search.js @@ -340,7 +340,8 @@ IPA.search_facet = function(spec) { for (var i=0; i