Skip to content

Commit

Permalink
save column settings to cookie value
Browse files Browse the repository at this point in the history
  • Loading branch information
vangheem committed Nov 18, 2013
1 parent 4965bd5 commit 88aa621
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
4 changes: 3 additions & 1 deletion js/patterns/structure/templates/table.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
<th><input type="checkbox" class="select-all" /></th>
<th>Title</th>
<% _.each(activeColumns, function(column){ %>
<th><%- availableColumns[column] %></th>
<% if(_.has(availableColumns, column)) { %>
<th><%- availableColumns[column] %></th>
<% } %>
<% }); %>
</tr>
</thead>
Expand Down
4 changes: 3 additions & 1 deletion js/patterns/structure/templates/tablerow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<% } %>
</td>
<% _.each(activeColumns, function(column){ %>
<td class="<%- column %>"><%- attributes[column] %></td>
<% if(_.has(availableColumns, column)) { %>
<td class="<%- column %>"><%- attributes[column] %></td>
<% } %>
<% }); %>

30 changes: 29 additions & 1 deletion js/patterns/structure/views/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ define([
'js/patterns/structure/views/textfilter',
'js/patterns/structure/collections/result',
'js/patterns/structure/collections/selected',
'mockup-patterns-dropzone'
'mockup-patterns-dropzone',
'jquery.cookie'
], function($, _, Backbone, Toolbar, ButtonGroup, ButtonView, BaseView,
TableView, SelectionWellView, TagsView, PropertiesView,
WorkflowView, DeleteView, RenameView, SelectionButtonView,
Expand Down Expand Up @@ -85,9 +86,11 @@ define([
sort_order: 'ascending',
additionalCriterias: [],
pasteSelection: null,
cookieSettingPrefix: '_fc_',
initialize: function(){
var self = this;
BaseView.prototype.initialize.call(self);
self.setAllCookieSettings();

self.collection = new ResultCollection([], {
url: self.options.collectionUrl
Expand Down Expand Up @@ -458,6 +461,31 @@ define([
}

return self;
},
getCookieSetting: function(name, _default){
if(_default === undefined){
_default = null;
}
var val;
try{
val = $.cookie(this.cookieSettingPrefix + name);
val = $.parseJSON(val).value;
}catch(e){
/* error parsing json, load default here now */
return _default;
}
if(val === undefined || val === null){
return _default;
}
return val;
},
setCookieSetting: function(name, val){
$.cookie(this.cookieSettingPrefix + name,
JSON.stringify({'value': val})
);
},
setAllCookieSettings: function(){
this.activeColumns = this.getCookieSetting('activeColumns', this.activeColumns);
}
});

Expand Down
3 changes: 2 additions & 1 deletion js/patterns/structure/views/columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ define([

return this;
},
applyButtonClicked: function(e){
applyButtonClicked: function(){
var self = this;
this.hide();
self.app.activeColumns = [];
self.$('input:checked').each(function(){
self.app.activeColumns.push($(this).val());
});
self.app.setCookieSetting('activeColumns', this.app.activeColumns);
self.app.tableView.render();
}
});
Expand Down
1 change: 1 addition & 0 deletions js/patterns/structure/views/tablerow.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ define([
}
data.attributes = this.model.attributes;
data.activeColumns = this.app.activeColumns;
data.availableColumns = this.app.availableColumns;
this.$el.html(this.template(data));
var attrs = this.model.attributes;
this.$el.addClass('state-' + attrs.review_state).
Expand Down

2 comments on commit 88aa621

@mister-roboto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TESTS FAILED
Mr.roboto url : http://jenkins.plone.org/roboto/get_info?push=66e94eb23a254c4582ace5bd24fed585
plone-5.0-python-2.7 [FAILURE]

@davisagli
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about localStorage instead of a cookie so it doesn't have to get sent to the server on every request?

Please sign in to comment.