Skip to content

Commit

Permalink
Ability to customize the cookie for columns
Browse files Browse the repository at this point in the history
- Define a new key "activeColumnsCookie" for structure.
- This enables view specific column settings (i.e. a view on a list of
  users may have sufficiently different columns such that the settings
  for folder_contents shouldn't apply or interfere with at all).
  • Loading branch information
metatoaster committed Dec 15, 2015
1 parent 6b79d3a commit e582a8a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
3 changes: 2 additions & 1 deletion mockup/patterns/structure/js/views/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ define([
);
},
setAllCookieSettings: function() {
this.activeColumns = this.getCookieSetting('activeColumns', this.activeColumns);
this.activeColumns = this.getCookieSetting(this['activeColumnsCookie'],
this.activeColumns);
var perPage = this.getCookieSetting('perPage', 15);
if(typeof(perPage) === 'string'){
perPage = parseInt(perPage);
Expand Down
2 changes: 1 addition & 1 deletion mockup/patterns/structure/js/views/columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ define([
self.$('input:checked').each(function() {
self.app.activeColumns.push($(this).val());
});
self.app.setCookieSetting('activeColumns', this.app.activeColumns);
self.app.setCookieSetting(self.app.activeColumnsCookie, this.app.activeColumns);
self.app.tableView.render();
}
});
Expand Down
1 change: 1 addition & 0 deletions mockup/patterns/structure/pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ define([
'EffectiveDate',
'review_state'
],
activeColumnsCookie: 'activeColumns',
availableColumns: {
'id': 'ID',
'ModificationDate': 'Last modified',
Expand Down
51 changes: 51 additions & 0 deletions mockup/tests/pattern-structure-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ define([
// clear cookie setting
$.removeCookie('_fc_perPage');
$.removeCookie('_fc_activeColumns');
$.removeCookie('_fc_activeColumnsCustom');

this.$el = $('' +
'<div class="pat-structure" ' +
Expand Down Expand Up @@ -344,6 +345,7 @@ define([
'{&quot;vocabularyUrl&quot;: &quot;/data.json;&quot;,' +
'&quot;indexOptionsUrl&quot;: &quot;/tests/json/queryStringCriteria.json&quot;,' +
'&quot;contextInfoUrl&quot;: &quot;{path}/contextInfo&quot;,' +
'&quot;activeColumnsCookie&quot;: &quot;activeColumnsCustom&quot;,' +
// XXX need a test where there are _no_ buttons.
'&quot;buttons&quot;: [{' +
'&quot;url&quot;: &quot;foo&quot;, ' +
Expand Down Expand Up @@ -442,6 +444,55 @@ define([
expect(this.$el.find('#btn-selected-items').html()).to.contain('0');
});

it('test select displayed columns', function() {
registry.scan(this.$el);
// manually setting a borrowed cookie from the previous test.
$.cookie('_fc_activeColumns',
'{"value":["ModificationDate","EffectiveDate","review_state",' +
'"getObjSize"]}');
this.clock.tick(500);
var $row = this.$el.find('table thead tr').eq(1);
expect($row.find('th').length).to.equal(6);
expect($row.find('th').eq(5).text()).to.equal('Actions');

expect($.cookie('_fc_activeColumnsCustom')).to.be(undefined);

this.$el.find('#btn-attribute-columns').trigger('click');
this.clock.tick(500);

var $checkbox = this.$el.find(
'.attribute-columns input[value="portal_type"]');
$checkbox[0].checked = true;
$checkbox.trigger('change');
this.clock.tick(500);

var $popover = this.$el.find('.popover.attribute-columns');
expect($popover.find('button').text()).to.equal('Save');
$popover.find('button').trigger('click');
this.clock.tick(500);

$row = this.$el.find('table thead tr').eq(1);
expect($row.find('th').length).to.equal(7);
expect($row.find('th').eq(5).text()).to.equal('Type');
expect($row.find('th').eq(6).text()).to.equal('Actions');
expect($.parseJSON($.cookie('_fc_activeColumnsCustom')).value).to.eql(
["ModificationDate", "EffectiveDate", "review_state", "portal_type"]);
// standard cookie unchanged.
expect($.parseJSON($.cookie('_fc_activeColumns')).value).to.eql(
["ModificationDate", "EffectiveDate", "review_state", "getObjSize"]);

$checkbox[0].checked = false;
$checkbox.trigger('change');
$popover.find('button').trigger('click');
this.clock.tick(500);

$row = this.$el.find('table thead tr').eq(1);
expect($row.find('th').length).to.equal(6);
expect($.parseJSON($.cookie('_fc_activeColumnsCustom')).value).to.eql(
["ModificationDate", "EffectiveDate", "review_state"]);

});

});


Expand Down

0 comments on commit e582a8a

Please sign in to comment.