summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2011-07-21 21:29:55 -0500
committerAdam Young <ayoung@redhat.com>2011-07-22 12:13:10 -0400
commitca7395c35367965f8824f2bfecfa3f79f4b8a87b (patch)
tree6258c97d760c56421a6e7dc47050216334073b4f
parentdf7ee2ccf5ff12ab43b1a97385b4f28bc64ef083 (diff)
downloadfreeipa-ca7395c35367965f8824f2bfecfa3f79f4b8a87b.tar.gz
freeipa-ca7395c35367965f8824f2bfecfa3f79f4b8a87b.tar.xz
freeipa-ca7395c35367965f8824f2bfecfa3f79f4b8a87b.zip
Refactored IPA.current_facet().
The IPA.current_facet() has been merged into IPA.entity.setup() and replaced by IPA.entity.get_facet(). The setup() will read the current facet's name from the <entity>-facet URL parameter and store the facet object in the entity object. The get_facet() without any parameter will return the current facet object.
-rw-r--r--install/ui/add.js6
-rw-r--r--install/ui/association.js6
-rw-r--r--install/ui/details.js6
-rw-r--r--install/ui/entitle.js12
-rw-r--r--install/ui/entity.js41
-rw-r--r--install/ui/navigation.js3
-rw-r--r--install/ui/user.js6
7 files changed, 32 insertions, 48 deletions
diff --git a/install/ui/add.js b/install/ui/add.js
index b6b797c45..614a20905 100644
--- a/install/ui/add.js
+++ b/install/ui/add.js
@@ -50,8 +50,7 @@ IPA.add_dialog = function (spec) {
that.add(
record,
function(data, text_status, xhr) {
- var facet_name = IPA.current_facet(IPA.current_entity);
- var facet = IPA.current_entity.get_facet(facet_name);
+ var facet = IPA.current_entity.get_facet();
var table = facet.table;
table.refresh();
that.close();
@@ -66,8 +65,7 @@ IPA.add_dialog = function (spec) {
that.add(
record,
function(data, text_status, xhr) {
- var facet_name = IPA.current_facet(IPA.current_entity);
- var facet = IPA.current_entity.get_facet(facet_name);
+ var facet = IPA.current_entity.get_facet();
var table = facet.table;
table.refresh();
that.reset();
diff --git a/install/ui/association.js b/install/ui/association.js
index 32b4c3697..5354117d0 100644
--- a/install/ui/association.js
+++ b/install/ui/association.js
@@ -382,8 +382,7 @@ IPA.association_table_widget = function (spec) {
}
var entity = IPA.get_entity(that.entity_name);
- var facet_name = IPA.current_facet(entity);
- var facet = entity.get_facet(facet_name);
+ var facet = entity.get_facet();
if (facet.is_dirty()) {
var dialog = IPA.dirty_dialog({
@@ -408,8 +407,7 @@ IPA.association_table_widget = function (spec) {
}
var entity = IPA.get_entity(that.entity_name);
- var facet_name = IPA.current_facet(entity);
- var facet = entity.get_facet(facet_name);
+ var facet = entity.get_facet();
if (facet.is_dirty()) {
var dialog = IPA.dirty_dialog({
diff --git a/install/ui/details.js b/install/ui/details.js
index 45ffa6f16..50fccce49 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -484,12 +484,10 @@ IPA.details_facet = function(spec) {
}
};
- function new_key(){
+ that.needs_update = function() {
var pkey = IPA.nav.get_state(that.entity_name+'-pkey');
return pkey != that.pkey;
- }
- that.new_key = new_key;
-
+ };
that.is_dirty = function() {
var sections = that.sections.values;
diff --git a/install/ui/entitle.js b/install/ui/entitle.js
index bbcf2395c..d0af1ab84 100644
--- a/install/ui/entitle.js
+++ b/install/ui/entitle.js
@@ -588,8 +588,7 @@ IPA.entitle.register_online_dialog = function(spec) {
record.password,
record.ipaentitlementid,
function() {
- var facet_name = IPA.current_facet(that.entity);
- var facet = that.entity.get_facet(facet_name);
+ var facet = that.entity.get_facet();
facet.refresh();
that.close();
}
@@ -613,8 +612,7 @@ IPA.entitle.register_offline_dialog = function(spec) {
that.entity.register_offline(
that.get_certificate(),
function() {
- var facet_name = IPA.current_facet(that.entity);
- var facet = that.entity.get_facet(facet_name);
+ var facet = that.entity.get_facet();
facet.refresh();
that.close();
}
@@ -646,8 +644,7 @@ IPA.entitle.consume_dialog = function(spec) {
that.entity.consume(
record.quantity,
function() {
- var facet_name = IPA.current_facet(that.entity);
- var facet = that.entity.get_facet(facet_name);
+ var facet = that.entity.get_facet();
facet.refresh();
that.close();
}
@@ -671,8 +668,7 @@ IPA.entitle.import_dialog = function(spec) {
that.entity.import_certificate(
that.get_certificate(),
function() {
- var facet_name = IPA.current_facet(that.entity);
- var facet = that.entity.get_facet(facet_name);
+ var facet = that.entity.get_facet();
facet.refresh();
that.close();
}
diff --git a/install/ui/entity.js b/install/ui/entity.js
index 0940c7d17..83687fe7e 100644
--- a/install/ui/entity.js
+++ b/install/ui/entity.js
@@ -127,6 +127,10 @@ IPA.facet = function (spec) {
that.header.load(data);
};
+ that.needs_update = function() {
+ return true;
+ };
+
that.is_dirty = function() {
return false;
};
@@ -459,7 +463,7 @@ IPA.entity = function (spec) {
that.facet_groups = $.ordered_map();
// current facet
- that.facet_name = null;
+ that.facet = null;
that.redirect_facet = spec.redirect_facet;
that.containing_entity = null;
@@ -490,7 +494,14 @@ IPA.entity = function (spec) {
};
that.get_facet = function(name) {
- if (name === 'default') {
+ if (name === undefined) {
+ // return the current facet
+ if (that.facet) return that.facet;
+
+ // return the main facet
+ return that.facets.values[0];
+
+ } else if (name === 'default') {
// return the first facet in the first facet group
var facet_groups = that.facet_groups.values;
for (var i=0; i<facet_groups.length; i++) {
@@ -541,22 +552,17 @@ IPA.entity = function (spec) {
that.setup = function(container) {
- var prev_facet = that.facet;
+ var prev_entity = IPA.current_entity;
+ var prev_facet = prev_entity ? prev_entity.facet : null;
IPA.current_entity = that;
- var facet_name = IPA.current_facet(that);
+ var facet_name = IPA.nav.get_state(that.name+'-facet');
that.facet = that.get_facet(facet_name);
- if (!that.facet) return;
- if (IPA.entity_name == that.name) {
- if (that.facet_name == that.facet.name) {
- if (that.facet.new_key && (!that.facet.new_key())) return;
- } else {
- that.facet_name = that.facet.name;
- }
- } else {
- IPA.entity_name = that.name;
+ // same entity, same facet, and doesn't need updating => return
+ if (that == prev_entity && that.facet == prev_facet && !that.facet.needs_update()) {
+ return;
}
if (prev_facet) {
@@ -613,15 +619,6 @@ IPA.entity = function (spec) {
return that;
};
-IPA.current_facet = function(entity) {
- var facet_name = IPA.nav.get_state(entity.name+'-facet');
- var facets = entity.facets.values;
- if (!facet_name && facets.length) {
- facet_name = facets[0].name;
- }
- return facet_name;
-};
-
IPA.nested_tab_labels = {};
IPA.get_nested_tab_label = function(entity_name){
diff --git a/install/ui/navigation.js b/install/ui/navigation.js
index be2936dca..92949735e 100644
--- a/install/ui/navigation.js
+++ b/install/ui/navigation.js
@@ -87,8 +87,7 @@ IPA.navigation = function(spec) {
that.push_state = function(params) {
if (IPA.current_entity) {
- var facet_name = IPA.current_facet(IPA.current_entity);
- var facet = IPA.current_entity.get_facet(facet_name);
+ var facet = IPA.current_entity.get_facet();
if (facet.is_dirty()) {
var dialog = IPA.dirty_dialog({
diff --git a/install/ui/user.js b/install/ui/user.js
index 5d104bfc6..fbcc72852 100644
--- a/install/ui/user.js
+++ b/install/ui/user.js
@@ -173,8 +173,7 @@ IPA.user_status_widget = function(spec) {
click: function() {
var entity = IPA.get_entity(that.entity_name);
- var facet_name = IPA.current_facet(entity);
- var facet = entity.get_facet(facet_name);
+ var facet = entity.get_facet();
if (facet.is_dirty()) {
var dialog = IPA.dirty_dialog({
@@ -257,8 +256,7 @@ IPA.user_status_widget = function(spec) {
action == 'activate',
function(data, textStatus, xhr) {
var entity = IPA.get_entity(that.entity_name);
- var facet_name = IPA.current_facet(entity);
- var facet = entity.get_facet(facet_name);
+ var facet = entity.get_facet();
facet.refresh();
dialog.close();
}