summaryrefslogtreecommitdiffstats
path: root/install
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2011-05-26 17:57:39 -0500
committerAdam Young <ayoung@redhat.com>2011-05-27 13:06:57 -0400
commitaa29a8a769c62b07cc4e6d82fc79846505cc9fa3 (patch)
tree2131098b113c2bfecf1830feff0c08b3b2d1aabc /install
parent17c3f9e84efcbeb3b5ae1de83d799974de3bb078 (diff)
downloadfreeipa-aa29a8a769c62b07cc4e6d82fc79846505cc9fa3.tar.gz
freeipa-aa29a8a769c62b07cc4e6d82fc79846505cc9fa3.tar.xz
freeipa-aa29a8a769c62b07cc4e6d82fc79846505cc9fa3.zip
Added Update and Reset buttons into Dirty dialog.
The Dirty dialogs have been combined into IPA.dirty_dialog. It provides the Update and Reset buttons with customizable callback. Previously the widget's dirty status is computed by comparing the old values with the new values. This method is sometimes inaccurate, so the is_dirty() method has been modified to simply return a flag which is set to true if the widget is changed. Ticket #896.
Diffstat (limited to 'install')
-rw-r--r--install/ui/aci.js7
-rw-r--r--install/ui/associate.js41
-rw-r--r--install/ui/details.js8
-rw-r--r--install/ui/dns.js6
-rw-r--r--install/ui/entity.js5
-rw-r--r--install/ui/hbac.js5
-rw-r--r--install/ui/ipa.js68
-rw-r--r--install/ui/navigation.js22
-rw-r--r--install/ui/sudo.js3
-rw-r--r--install/ui/test/widget_tests.js9
-rw-r--r--install/ui/widget.js134
11 files changed, 142 insertions, 166 deletions
diff --git a/install/ui/aci.js b/install/ui/aci.js
index 336a965fc..d507e2d07 100644
--- a/install/ui/aci.js
+++ b/install/ui/aci.js
@@ -233,7 +233,7 @@ IPA.attributes_widget = function(spec) {
click: function(){
$('.aci-attribute', that.table).
attr('checked', $(this).attr('checked'));
- that.show_undo();
+ that.set_dirty(true);
}
})
})).append($('<th/>', {
@@ -245,7 +245,6 @@ IPA.attributes_widget = function(spec) {
that.create_undo(container);
that.get_undo().click(function(){
that.reset();
- that.hide_undo();
});
}
@@ -298,7 +297,7 @@ IPA.attributes_widget = function(spec) {
value: value,
'class': 'aci-attribute',
click: function() {
- that.show_undo();
+ that.set_dirty(true);
}
}));
td = $('<td/>').appendTo(aci_tr);
@@ -335,7 +334,7 @@ IPA.attributes_widget = function(spec) {
value: value,
'class': 'aci-attribute',
change: function() {
- that.show_undo();
+ that.set_dirty(true);
}
}));
diff --git a/install/ui/associate.js b/install/ui/associate.js
index 3ba510f10..5eb84260e 100644
--- a/install/ui/associate.js
+++ b/install/ui/associate.js
@@ -348,7 +348,6 @@ IPA.association_table_widget = function (spec) {
that.create = function(container) {
- var entity = IPA.get_entity(that.entity_name);
var column;
// create a column if none defined
@@ -395,21 +394,6 @@ IPA.association_table_widget = function (spec) {
that.table_setup(container);
- var dialog = IPA.dialog({
- title: IPA.messages.dialogs.dirty_title,
- width: '20em'
- });
-
- dialog.create = function() {
- dialog.container.append(IPA.messages.dialogs.dirty_message);
- };
-
- dialog.add_button(IPA.messages.buttons.ok, function() {
- dialog.close();
- });
-
- dialog.init();
-
var entity = IPA.get_entity(that.entity_name);
var facet_name = IPA.current_facet(entity);
var facet = entity.get_facet(facet_name);
@@ -424,7 +408,17 @@ IPA.association_table_widget = function (spec) {
}
if (facet.is_dirty()) {
+ var dialog = IPA.dirty_dialog({
+ facet: facet
+ });
+
+ dialog.callback = function() {
+ that.show_remove_dialog();
+ };
+
+ dialog.init();
dialog.open(that.container);
+
} else {
that.show_remove_dialog();
}
@@ -443,7 +437,17 @@ IPA.association_table_widget = function (spec) {
}
if (facet.is_dirty()) {
+ var dialog = IPA.dirty_dialog({
+ facet: facet
+ });
+
+ dialog.callback = function() {
+ that.show_add_dialog();
+ };
+
+ dialog.init();
dialog.open(that.container);
+
} else {
that.show_add_dialog();
}
@@ -809,11 +813,6 @@ IPA.association_facet = function (spec) {
that.table.init();
};
- that.is_dirty = function() {
- var pkey = $.bbq.getState(that.entity_name+'-pkey');
- return pkey != that.pkey;
- };
-
that.create_header = function(container) {
that.facet_create_header(container);
diff --git a/install/ui/details.js b/install/ui/details.js
index 4af837e8e..4aa864fed 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -496,14 +496,11 @@ IPA.details_facet = function(spec) {
that.is_dirty = function() {
-
- var i;
- for ( i =0; i < that.sections.length; i +=1 ){
- if (that.sections[i].is_dirty()){
+ for (var i=0; i<that.sections.length; i++) {
+ if (that.sections[i].is_dirty()) {
return true;
}
}
-
return false;
};
@@ -558,7 +555,6 @@ IPA.details_facet = function(spec) {
for (var j=0; j<section_fields.length; j++) {
var field = section_fields[j];
- var span = $('span[name='+field.name+']', section.container).first();
values = field.save();
if (!values) continue;
diff --git a/install/ui/dns.js b/install/ui/dns.js
index 1c0ff6eef..ff4294524 100644
--- a/install/ui/dns.js
+++ b/install/ui/dns.js
@@ -329,12 +329,6 @@ IPA.records_facet = function(spec) {
dialog.open(that.container);
};
- that.is_dirty = function() {
- var pkey = $.bbq.getState(that.entity_name+'-pkey');
- var record = $.bbq.getState(that.entity_name+'-record');
- return pkey != that.pkey || record != that.record;
- };
-
that.create_header = function(container) {
that.facet_create_header(container);
diff --git a/install/ui/entity.js b/install/ui/entity.js
index c855da1b5..4b6ce1d0e 100644
--- a/install/ui/entity.js
+++ b/install/ui/entity.js
@@ -122,7 +122,7 @@ IPA.facet = function (spec) {
that.load = function() {
};
- that.is_dirty = function (){
+ that.is_dirty = function() {
return false;
};
@@ -536,10 +536,7 @@ IPA.entity_header = function(spec) {
}
var pkey = $.bbq.getState(that.entity.name+'-pkey');
-
IPA.nav.show_page(that.entity.name, other_facet.name, pkey);
- $('a', that.facet_tabs).removeClass('selected');
- $('a', li).addClass('selected');
return false;
}
diff --git a/install/ui/hbac.js b/install/ui/hbac.js
index aa11879b8..4d46a18f5 100644
--- a/install/ui/hbac.js
+++ b/install/ui/hbac.js
@@ -438,7 +438,6 @@ IPA.hbacrule_details_facet = function (spec) {
for (var j=0; j<section_fields.length; j++) {
var field = section_fields[j];
- var span = $('span[name='+field.name+']', section.container).first();
var values = field.save();
if (!values) continue;
@@ -461,7 +460,7 @@ IPA.hbacrule_details_facet = function (spec) {
}
// skip unchanged field
- if (!field.is_dirty(span)) continue;
+ if (!field.is_dirty()) continue;
// check enable/disable
if (field.name == 'ipaenabledflag') {
@@ -795,7 +794,7 @@ IPA.hbacrule_accesstime_widget = function (spec) {
var input = $('input[name="'+that.name+'"]', that.container);
input.change(function() {
- that.show_undo();
+ that.set_dirty(true);
});
var undo = that.get_undo();
diff --git a/install/ui/ipa.js b/install/ui/ipa.js
index 0266e3499..7fd784b54 100644
--- a/install/ui/ipa.js
+++ b/install/ui/ipa.js
@@ -155,37 +155,6 @@ var IPA = ( function () {
that.entities.remove(name);
};
- that.test_dirty = function(){
- if (IPA.current_entity){
- var facet_name = IPA.current_facet(IPA.current_entity);
- var facet = IPA.current_entity.get_facet(facet_name);
- if (!facet) return false;
-
- if (facet.is_dirty()){
-
- var dialog = IPA.dialog({
- title: IPA.messages.dialogs.dirty_title,
- width: '20em'
- });
-
- dialog.create = function() {
- dialog.container.append(IPA.messages.dialogs.dirty_message);
- };
-
- dialog.add_button(IPA.messages.buttons.ok, function() {
- dialog.close();
- });
-
- dialog.init();
-
- dialog.open($('#navigation'));
-
- return false;
- }
- }
- return true;
- };
-
that.display_activity_icon = function() {
that.network_call_count++;
$('.network-activity-indicator').css('visibility', 'visible');
@@ -578,3 +547,40 @@ IPA.create_network_spinner = function(){
'class':'network-activity-indicator',
html: '<img src="spinner_small.gif" />'});
};
+
+IPA.dirty_dialog = function(spec) {
+
+ spec = spec || {};
+ spec.title = spec.title || IPA.messages.dialogs.dirty_title;
+ spec.width = spec.width || '25em';
+
+ var that = IPA.dialog(spec);
+ that.facet = spec.facet;
+ that.message = spec.message || IPA.messages.dialogs.dirty_message;
+
+ that.create = function() {
+ that.container.append(that.message);
+ };
+
+ that.add_button(IPA.messages.buttons.update, function() {
+ that.facet.update(function() {
+ that.close();
+ that.callback();
+ });
+ });
+
+ that.add_button(IPA.messages.buttons.reset, function() {
+ that.facet.reset();
+ that.close();
+ that.callback();
+ });
+
+ that.add_button(IPA.messages.buttons.cancel, function() {
+ that.close();
+ });
+
+ that.callback = function() {
+ };
+
+ return that;
+}; \ No newline at end of file
diff --git a/install/ui/navigation.js b/install/ui/navigation.js
index 379573910..11520ff91 100644
--- a/install/ui/navigation.js
+++ b/install/ui/navigation.js
@@ -80,9 +80,27 @@ IPA.navigation = function(spec) {
};
that.push_state = function(params) {
- if (!IPA.test_dirty()) {
- return false;
+
+ if (IPA.current_entity) {
+ var facet_name = IPA.current_facet(IPA.current_entity);
+ var facet = IPA.current_entity.get_facet(facet_name);
+
+ if (facet.is_dirty()) {
+ var dialog = IPA.dirty_dialog({
+ facet: facet
+ });
+
+ dialog.callback = function() {
+ $.bbq.pushState(params);
+ };
+
+ dialog.init();
+ dialog.open($('#navigation'));
+
+ return false;
+ }
}
+
$.bbq.pushState(params);
return true;
};
diff --git a/install/ui/sudo.js b/install/ui/sudo.js
index 7bd6f4500..89b7101bd 100644
--- a/install/ui/sudo.js
+++ b/install/ui/sudo.js
@@ -454,7 +454,6 @@ IPA.sudorule_details_facet = function (spec) {
for (var j=0; j<section_fields.length; j++) {
var field = section_fields[j];
- var span = $('span[name='+field.name+']', section.container).first();
var values = field.save();
if (!values) continue;
@@ -477,7 +476,7 @@ IPA.sudorule_details_facet = function (spec) {
}
// skip unchanged field
- if (!field.is_dirty(span)) continue;
+ if (!field.is_dirty()) continue;
// check enable/disable
if (field.name == 'ipaenabledflag') {
diff --git a/install/ui/test/widget_tests.js b/install/ui/test/widget_tests.js
index f4281e38f..f323f9697 100644
--- a/install/ui/test/widget_tests.js
+++ b/install/ui/test/widget_tests.js
@@ -185,13 +185,14 @@ test("IPA.table_widget" ,function(){
test("Testing base widget.", function() {
var update_called = false;
var spec = {
- name:'title',
- update:function(){
- update_called = true;
- }
+ name:'title'
};
var widget = IPA.widget(spec);
+ widget.update = function() {
+ update_called = true;
+ };
+
base_widget_test(widget,'user','test_value');
widget_string_test(widget);
ok (update_called, 'Update called');
diff --git a/install/ui/widget.js b/install/ui/widget.js
index 6b211d6f4..66dedbdfe 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -51,17 +51,11 @@ IPA.widget = function(spec) {
that.undo = typeof spec.undo == 'undefined' ? true : spec.undo;
that.join = spec.join;
- that.init = spec.init || init;
- that.create = spec.create || create;
- that.setup = spec.setup || setup;
- that.load = spec.load || load;
- that.save = spec.save || save;
- that.update = spec.update || update;
-
that.param_info = spec.param_info;
that.metadata = spec.metadata;
that.values = [];
+ that.dirty = false;
that.valid = true;
that.__defineGetter__("entity_name", function(){
@@ -128,7 +122,7 @@ IPA.widget = function(spec) {
}
};
- function init() {
+ that.init = function() {
if (that.entity_name) {
that.param_info = IPA.get_entity_param(that.entity_name, that.name);
@@ -143,20 +137,20 @@ IPA.widget = function(spec) {
}
}
}
- }
+ };
- function create(container) {
- }
+ that.create = function(container) {
+ };
- function setup(container) {
+ that.setup = function(container) {
that.container = container;
- }
+ };
/**
* This function stores the entire record and the values
* of the field, then invoke reset() to update the UI.
*/
- function load(record) {
+ that.load = function(record) {
that.record = record;
var value = record[that.name];
@@ -186,24 +180,24 @@ IPA.widget = function(spec) {
}
that.reset();
- }
+ };
that.reset = function() {
- that.hide_undo();
+ that.set_dirty(false);
that.update();
};
- function update() {
- }
+ that.update = function() {
+ };
/**
* This function saves the values entered in the UI.
* It returns the values in an array, or null if
* the field should not be saved.
*/
- function save() {
+ that.save = function() {
return that.values;
- }
+ };
/**
* This function compares the original values and the
@@ -211,45 +205,7 @@ IPA.widget = function(spec) {
* it will return true.
*/
that.is_dirty = function() {
-
- if (that.read_only) {
- return false;
- }
-
- var values = that.save();
-
- if (!values) { // ignore null values
- return false;
- }
-
- if (!that.values) {
-
- if (values instanceof Array) {
-
- if ((values.length === 0) ||
- (values.length === 1) &&
- (values[0] === '')) {
- return false;
- }
- }
-
- return true;
- }
-
- if (values.length != that.values.length) {
- return true;
- }
-
- values.sort();
- that.values.sort();
-
- for (var i=0; i<values.length; i++) {
- if (values[i] != that.values[i]) {
- return true;
- }
- }
-
- return false;
+ return that.dirty;
};
that.create_undo = function(container) {
@@ -262,6 +218,17 @@ IPA.widget = function(spec) {
}).appendTo(container);
};
+ that.set_dirty = function(dirty) {
+ that.dirty = dirty;
+ if (that.undo) {
+ if (dirty) {
+ that.show_undo();
+ } else {
+ that.hide_undo();
+ }
+ }
+ };
+
that.get_undo = function() {
return $(that.undo_span);
};
@@ -302,6 +269,7 @@ IPA.widget = function(spec) {
that.widget_load = that.load;
that.widget_reset = that.reset;
that.widget_save = that.save;
+ that.widget_set_dirty = that.set_dirty;
return that;
};
@@ -352,9 +320,7 @@ IPA.text_widget = function(spec) {
var input = $('input[name="'+that.name+'"]', that.container);
input.keyup(function() {
- if (that.undo) {
- that.show_undo();
- }
+ that.set_dirty(true);
that.validate();
});
@@ -418,6 +384,17 @@ IPA.multivalued_text_widget = function(spec) {
}
};
+ that.set_dirty = function(dirty, index) {
+ that.widget_set_dirty(dirty);
+ if (that.undo) {
+ if (dirty) {
+ that.show_undo(index);
+ } else {
+ that.hide_undo(index);
+ }
+ }
+ };
+
that.show_undo = function(index) {
var undo = that.get_undo(index);
undo.css('display', 'inline');
@@ -550,9 +527,8 @@ IPA.multivalued_text_widget = function(spec) {
var index = that.row_index(row);
if (index >= that.values.length) {
// show undo/remove link for new value
+ that.set_dirty(true, index);
if (that.undo) {
- that.show_undo(index);
- that.show_undo();
remove_link.css('display', 'none');
} else {
remove_link.css('display', 'inline');
@@ -563,9 +539,8 @@ IPA.multivalued_text_widget = function(spec) {
var index = that.row_index(row);
// uncross removed value
input.removeClass('strikethrough');
+ that.set_dirty(true, index);
if (that.undo) {
- that.show_undo(index);
- that.show_undo();
if (index < that.values.length) {
remove_link.css('display', 'inline');
}
@@ -579,10 +554,7 @@ IPA.multivalued_text_widget = function(spec) {
// restore old value then cross it out
that.update(index);
input.addClass('strikethrough');
- if (that.undo) {
- that.show_undo(index);
- that.show_undo();
- }
+ that.set_dirty(true, index);
remove_link.css('display', 'none');
} else {
// remove new value
@@ -623,7 +595,7 @@ IPA.multivalued_text_widget = function(spec) {
};
that.reset = function(index) {
- that.hide_undo(index);
+ that.set_dirty(false, index);
that.update(index);
};
@@ -685,7 +657,7 @@ IPA.checkbox_widget = function (spec) {
var input = $('input[name="'+that.name+'"]', that.container);
input.change(function() {
- that.show_undo();
+ that.set_dirty(true);
});
var undo = that.get_undo();
@@ -759,7 +731,7 @@ IPA.checkboxes_widget = function (spec) {
var input = $('input[name="'+that.name+'"]', that.container);
input.change(function() {
- that.show_undo();
+ that.set_dirty(true);
});
var undo = that.get_undo();
@@ -837,7 +809,7 @@ IPA.radio_widget = function(spec) {
var input = $('input[name="'+that.name+'"]', that.container);
input.change(function() {
- that.show_undo();
+ that.set_dirty(true);
});
var undo = that.get_undo();
@@ -913,7 +885,7 @@ IPA.select_widget = function(spec) {
that.select = $('select[name="'+that.name+'"]', that.container);
that.select.change(function() {
- that.show_undo();
+ that.set_dirty(true);
});
var undo = that.get_undo();
@@ -994,7 +966,7 @@ IPA.textarea_widget = function (spec) {
var input = $('textarea[name="'+that.name+'"]', that.container);
input.keyup(function() {
- that.show_undo();
+ that.set_dirty(true);
that.validate();
});
@@ -1439,7 +1411,7 @@ IPA.entity_select_widget = function(spec) {
that.entity_select = $('<select/>', {
id: that.name + '-entity-select',
change: function(){
- that.show_undo();
+ that.set_dirty(true);
}
}).appendTo(container);
@@ -1450,7 +1422,7 @@ IPA.entity_select_widget = function(spec) {
style: 'display: none;',
keyup: function(){
populate_select();
- that.show_undo();
+ that.set_dirty(true);
}
}).appendTo(container);
@@ -1477,14 +1449,10 @@ IPA.entity_select_widget = function(spec) {
that.reset = function() {
that.entity_filter.val(that.values[0]);
- that.hide_undo();
+ that.set_dirty(false);
populate_select(that.values[0]);
};
- that.is_dirty = function() {
- return (that.save()[0] !== that.values[0]);
- };
-
that.load = function(record) {
var value = record[that.name];
if (value instanceof Array) {