summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--install/ui/association.js72
-rw-r--r--install/ui/entity.js19
-rw-r--r--install/ui/widget.js51
3 files changed, 85 insertions, 57 deletions
diff --git a/install/ui/association.js b/install/ui/association.js
index 3c847c59c..883bb2b42 100644
--- a/install/ui/association.js
+++ b/install/ui/association.js
@@ -671,7 +671,7 @@ IPA.association_facet = function (spec) {
spec = spec || {};
- var that = IPA.facet(spec);
+ var that = IPA.table_facet(spec);
that.attribute_member = spec.attribute_member;
that.indirect_attribute_member = spec.indirect_attribute_member;
@@ -688,49 +688,34 @@ IPA.association_facet = function (spec) {
that.add_method = spec.add_method || 'add_member';
that.remove_method = spec.remove_method || 'remove_member';
- that.columns = $.ordered_map();
that.adder_columns = $.ordered_map();
that.page_length = spec.page_length === undefined ? 20 : spec.page_length;
- that.get_column = function(name) {
- return that.columns.get(name);
- };
-
- that.add_column = function(column) {
- that.columns.put(column.name, column);
- };
-
- that.create_column = function(spec) {
- var column = IPA.column(spec);
- that.add_column(column);
- return column;
- };
-
that.get_adder_column = function(name) {
return that.adder_columns.get(name);
};
that.add_adder_column = function(column) {
+ column.entity_name = that.managed_entity_name;
that.adder_columns.put(column.name, column);
};
that.create_adder_column = function(spec) {
- var column = IPA.column(spec);
+ var column;
+ if (spec instanceof Object) {
+ var factory = spec.factory || IPA.column;
+ column = factory(spec);
+ } else {
+ column = IPA.column({ name: spec });
+ }
that.add_adder_column(column);
return column;
};
- var i;
- if (spec.columns){
- for (i = 0; i < spec.columns.length; i+= 1){
- that.create_column(spec.columns[i]);
- }
- }
- if (spec.adder_columns){
- for (i = 0; i < spec.adder_columns.length; i+= 1){
- that.create_adder_column(spec.adder_columns[i]);
- }
+ var adder_columns = spec.adder_columns || [];
+ for (var i=0; i<adder_columns.length; i++) {
+ that.create_adder_column(adder_columns[i]);
}
that.init = function() {
@@ -785,7 +770,38 @@ IPA.association_facet = function (spec) {
column.entity_name = that.other_entity;
}
+ that.table.prev_page = function() {
+ if (that.table.current_page > 1) {
+ IPA.nav.push_state({ page: that.table.current_page-1 });
+ }
+ };
+
+ that.table.next_page = function() {
+ if (that.table.current_page < that.table.total_pages) {
+ IPA.nav.push_state({ page: that.table.current_page+1 });
+ }
+ };
+
+ that.table.set_page = function(page) {
+ if (page < 1) {
+ page = 1;
+ } else if (page > that.total_pages) {
+ page = that.total_pages;
+ }
+ IPA.nav.push_state({ page: page });
+ };
+
that.table.refresh = function() {
+ var page = parseInt(IPA.nav.get_state('page'), 10) || 1;
+ if (page < 1) {
+ IPA.nav.push_state({ page: 1 });
+ return;
+ } else if (page > that.table.total_pages) {
+ IPA.nav.push_state({ page: that.table.total_pages });
+ return;
+ }
+ that.table.current_page = page;
+ that.table.current_page_input.val(page);
that.refresh_table();
};
@@ -1095,7 +1111,7 @@ IPA.association_facet = function (spec) {
that.table.total_pages = 1;
}
- that.refresh_table();
+ that.table.refresh();
}
var pkey = IPA.get_entity(that.entity_name).get_primary_key();
diff --git a/install/ui/entity.js b/install/ui/entity.js
index 8ccdb8ea2..c6d46ab74 100644
--- a/install/ui/entity.js
+++ b/install/ui/entity.js
@@ -188,7 +188,13 @@ IPA.table_facet = function(spec) {
};
that.create_column = function(spec) {
- var column = IPA.column(spec);
+ var column;
+ if (spec instanceof Object) {
+ var factory = spec.factory || IPA.column;
+ column = factory(spec);
+ } else {
+ column = IPA.column({ name: spec });
+ }
that.add_column(column);
return column;
};
@@ -200,16 +206,7 @@ IPA.table_facet = function(spec) {
var columns = spec.columns || [];
for (var i=0; i<columns.length; i++) {
- var column_spec = columns[i];
- var column;
-
- if (column_spec instanceof Object) {
- var factory = column_spec.factory || IPA.column;
- column = factory(column_spec);
- } else {
- column = IPA.column({ name: column_spec });
- }
- that.add_column(column);
+ that.create_column(columns[i]);
}
return that;
diff --git a/install/ui/widget.js b/install/ui/widget.js
index 80906a2f5..b486145bd 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -1334,10 +1334,7 @@ IPA.table_widget = function (spec) {
text: 'Prev',
name: 'prev_page',
click: function() {
- if (that.current_page > 1) {
- that.current_page--;
- that.refresh();
- }
+ that.prev_page();
return false;
}
}).appendTo(that.pagination);
@@ -1348,10 +1345,7 @@ IPA.table_widget = function (spec) {
text: 'Next',
name: 'next_page',
click: function() {
- if (that.current_page < that.total_pages) {
- that.current_page++;
- that.refresh();
- }
+ that.next_page();
return false;
}
}).appendTo(that.pagination);
@@ -1363,15 +1357,8 @@ IPA.table_widget = function (spec) {
name: 'current_page',
keypress: function(e) {
if (e.which == 13) {
- var page = parseInt($(this).val(), 10);
- if (page < 1) {
- page = 1;
- } else if (page > that.total_pages) {
- page = that.total_pages;
- }
- that.current_page = page;
- $(this).val(page);
- that.refresh();
+ var page = parseInt(that.current_page_input.val(), 10) || 1;
+ that.set_page(page);
}
}
}).appendTo(that.pagination);
@@ -1384,7 +1371,32 @@ IPA.table_widget = function (spec) {
}
};
- that.select_changed = function(){
+ that.prev_page = function() {
+ if (that.current_page > 1) {
+ that.current_page--;
+ that.refresh();
+ }
+ };
+
+ that.next_page = function() {
+ if (that.current_page < that.total_pages) {
+ that.current_page++;
+ that.refresh();
+ }
+ };
+
+ that.set_page = function(page) {
+ if (page < 1) {
+ page = 1;
+ } else if (page > that.total_pages) {
+ page = that.total_pages;
+ }
+ that.current_page = page;
+ that.current_page_input.val(page);
+ that.refresh();
+ };
+
+ that.select_changed = function() {
};
that.setup = function(container) {
@@ -1521,6 +1533,9 @@ IPA.table_widget = function (spec) {
that.table_create = that.create;
that.table_setup = that.setup;
that.table_set_enabled = that.set_enabled;
+ that.table_prev_page = that.prev_page;
+ that.table_next_page = that.next_page;
+ that.table_set_page = that.set_page;
return that;
};