If a page is dirty, do not allow additional navigation until changes are saved or committed
https://fedorahosted.org/freeipa/ticket/726
This commit is contained in:
Adam Young 2011-01-26 20:58:06 -05:00
parent 7462a852bd
commit d7f4d616df
8 changed files with 130 additions and 23 deletions

View File

@ -49,6 +49,16 @@ IPA.details_field = function (spec) {
that.record = record;
that.values = record[that.name];
that.reset();
var param_info = IPA.get_param_info(that.entity_name, that.name);
if (param_info) {
if (param_info['primary_key']) {
that.read_only = true;
}
if ('no_update' in param_info['flags']) {
that.read_only = true;
}
}
}
that.update = function() {
@ -129,7 +139,10 @@ IPA.details_field = function (spec) {
var label = $('<label/>', { html:value.toString() });
if (!IPA.is_field_writable(rights)) return label;
if (!IPA.is_field_writable(rights)) {
that.read_only = true;
return label;
}
var param_info = IPA.get_param_info(that.entity_name, that.name);
if (param_info) {
@ -191,6 +204,7 @@ IPA.details_field = function (spec) {
}).appendTo(span) ;
if (!IPA.is_field_writable(rights)) {
that.read_only = true;
input.attr('disabled', 'disabled');
}
@ -383,6 +397,16 @@ IPA.details_section = function (spec){
}
};
that.is_dirty = function(){
for (var i=0; i<that.fields.length; i++) {
var field = that.fields[i];
if (field.is_dirty()){
return true;
}
}
return false;
}
// methods that should be invoked by subclasses
that.section_init = that.init;
that.section_create = that.create;
@ -653,10 +677,24 @@ IPA.details_facet = function (spec) {
}
}
function is_dirty() {
function new_key(){
var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
return pkey != that.pkey;
}
that.new_key = new_key;
function is_dirty() {
var i;
for ( i =0; i < that.sections.length; i +=1 ){
if (that.sections[i].is_dirty()){
return true;
}
}
return false;
}
function load(record) {
that.record = record;

View File

@ -63,6 +63,10 @@ IPA.facet = function (spec) {
function load() {
}
that.is_dirty = function (){
return false;
}
that.get_client_area = function() {
return $('.client', that.container);
};
@ -371,6 +375,7 @@ IPA.entity_setup = function (container) {
var entity = this;
IPA.current_entity = this;
var facet_name = IPA.current_facet(entity);
@ -379,8 +384,7 @@ IPA.entity_setup = function (container) {
if (IPA.entity_name == entity.name) {
if (entity.facet_name == facet_name) {
if (!facet.is_dirty()) return;
if (facet.new_key && (!facet.new_key())) return;
} else {
entity.facet_name = facet_name;
}

View File

@ -131,7 +131,38 @@ var IPA = ( function () {
}
};
that.test_dirty = function(){
if (IPA.current_entity){
var facet_name = IPA.current_facet(IPA.current_entity);
var facet = IPA.current_entity.facets_by_name[facet_name];
if (facet.is_dirty()){
var message_box = $("<div/>",{
html: IPA.messages.dirty
}).
appendTo($("#navigation"));
message_box.dialog({
title: 'Dirty',
modal:true,
width: '20em',
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
return false;
}
}
return true;
}
that.show_page = function (entity_name, facet_name) {
if (!IPA.test_dirty()){
return false;
}
var state = {};
state[entity_name + '-facet'] = facet_name;
@ -139,6 +170,11 @@ var IPA = ( function () {
};
that.switch_and_show_page = function (this_entity, facet_name, pkey) {
if (!IPA.test_dirty()){
return false;
}
if (!pkey){
that.show_page(this_entity, facet_name);
return;

View File

@ -23,9 +23,15 @@
var nav_tabs_lists;
var nav_container;
function nav_push_state(params)
{
if (!IPA.test_dirty()){
return false;
}
$.bbq.pushState(params);
return true;
}
function nav_get_state(key)
@ -58,8 +64,7 @@ function nav_create(nls, container, tabclass)
var id = parent.attr('id');
var state = {};
state[id] = ui.index;
nav_push_state(state);
return true;
return nav_push_state(state);
}
});

View File

@ -7398,6 +7398,7 @@
"misc": "Misc. Information",
"to_top": "Back to Top"
},
"dirty": "This page has unsaved changes. Please save or revert.",
"facets": {
"details": "Settings",
"search": "Search"
@ -7447,7 +7448,7 @@
"20110126193538Z"
],
"krblastsuccessfulauth": [
"20110126194824Z"
"20110127024034Z"
],
"krbpasswordexpiration": [
"20110426193538Z"

View File

@ -116,6 +116,12 @@ IPA.tab_state = function(entity_name){
/* main (document onready event handler) */
$(function() {
/* main loop (hashchange event handler) */
function window_hashchange(evt){
nav_update_tabs();
}
function should_show_all_ui(){
var whoami = IPA.whoami;
@ -167,13 +173,3 @@ $(function() {
IPA.init(null, null, init_on_win, init_on_error);
});
/* main loop (hashchange event handler) */
function window_hashchange(evt){
nav_update_tabs();
}
/* builder function for unimplemented tab content */
function unimplemented_tab(jobj){
jobj.text('Not implemented yet!');
}

View File

@ -126,14 +126,40 @@ IPA.widget = function(spec) {
}
that.is_dirty = function() {
if (that.read_only) {
return false;
}
var values = that.save();
if (!values && !that.values) return false;
if (!values || !that.values) return true;
if (values.length != that.values.length) return true;
if (!that.values){
if (!values) {
return false;
}
if ( values === "" ){
return false;
}
if ((values instanceof Array) &&
(values.length ===1) &&
(values[0] === "")){
return false;
}
if ((values instanceof Array) &&
(values.length === 0)){
return false;
}
if (values) {
return true;
}
}
if (values.length != that.values.length) {
return true;
}
for (var i=0; i<values.length; i++) {
if (values[i] != that.values[i]) return true;
if (values[i] != that.values[i]) {
return true;
}
}
return false;

View File

@ -122,7 +122,8 @@ class i18n_messages(Command):
"If this is your first time running the IPA Web UI"+
"<a href='/ipa/errors/ssbrowser.html'> "+
"Follow these directions</a> to configure your browser.")
}
},
"dirty":_("This page has unsaved changes. Please save or revert."),
}
has_output = (
Output('messages', dict, doc=_('Dict of I18N messages')),