Commit efbee5b9 authored by gijs's avatar gijs

Make line state persistent after save

parent 4c232eca
......@@ -74,6 +74,15 @@ window.W = window.W || {};
}
}
function initState() {
return {
'collapsed': {},
'expandLevel': 1
}
};
var state = initState();
/**
* Instantiate with at least a label.
*/
......@@ -496,7 +505,10 @@ window.W = window.W || {};
this.model.unset('alternative_p');
this.model.unset('alternative_mode');
this.editMode = false;
this.collapsed = true;
if (!(this.model.cid in state.collapsed)) {
state.collapsed[this.model.cid] = true;
}
this.listenTo(this.model, 'change', this.render);
},
......@@ -753,18 +765,19 @@ window.W = window.W || {};
// inverts the data-collapsed option
// Uses CSS to toggle visibility
this.collapsed = !this.collapsed;
this.$el.attr("data-collapsed", this.collapsed);
state.collapsed[this.model.cid] = !state.collapsed[this.model.cid];
this.$el.attr("data-collapsed", state.collapsed[this.model.cid]);
},
collapse: function () {
this.collapsed = true;
this.$el.attr("data-collapsed", this.collapsed);
state.collapsed[this.model.cid] = true;
this.$el.attr("data-collapsed", state.collapsed[this.model.cid]);
},
expand: function () {
this.collapsed = false
this.$el.attr("data-collapsed", this.collapsed);
state.collapsed[this.model.cid] = false;
this.$el.attr("data-collapsed", state.collapsed[this.model.cid]);
},
getAltSymbol: function () {
......@@ -839,7 +852,7 @@ window.W = window.W || {};
onRender: function () {
// attribut des attributs html pour styler en css
this.$el.attr("data-collapsed", this.collapsed);
this.$el.attr("data-collapsed", state.collapsed[this.model.cid]);
this.$el.attr("data-module", this.model.get("module_"));
this.$el.attr("data-contingent", this.model.get("contingent"));
......@@ -847,11 +860,9 @@ window.W = window.W || {};
//show mainline nodes if they are present
if (sublines.length) {
var treeView = new W.TreeView({
collection: sublines
});
var sublinesView = new W.TreeView({ collection: sublines });
this.showChildView('tree', treeView);
this.showChildView('tree', sublinesView);
}
}
});
......@@ -998,7 +1009,7 @@ window.W = window.W || {};
},
regions: {
firstRegion: 'ol',
mainline: 'ol',
form: {
el: '#sidebar form',
......@@ -1050,6 +1061,8 @@ window.W = window.W || {};
initialize: function () {
this.hasChanges = false;
this.metaToggled = false;
this.mainlineView = null;
this.sliderView = null;
// this.listenTo(this.model, 'change', this.render);
// this.listenTo(this.model, 'sync', this.render);
......@@ -1064,7 +1077,7 @@ window.W = window.W || {};
this.listenToOnce(this.model, 'sync', (function () {
this.listenTo(this.model, 'change', this.render);
this.listenTo(this.model, 'sync', this.render);
// this.listenTo(this.model, 'sync', this.render);
}).bind(this));
},
......@@ -1113,7 +1126,8 @@ window.W = window.W || {};
button.prop('disabled', true);
button.text(button.data('label-progress'));
this.model.save({}, {
this.model.save(null, {
silent: true,
success: function () {
button.text(button.data('label'));
},
......@@ -1158,27 +1172,20 @@ window.W = window.W || {};
},
expandUntill: function (level) {
this.getChildView('firstRegion').triggerMethod('expandUntill', level);
this.getChildView('mainline').triggerMethod('expandUntill', level);
},
onRender: function () {
document.title = this.model.get('title');
var mainline = this.model.get("mainline");
this.showChildView('firstRegion', new W.TreeNode({
model: mainline
}));
var mainlineView = new W.TreeNode({ model: this.model.get('mainline') });
this.showChildView('mainline', mainlineView);
var sliderView = new W.SliderView({ depth: this.model.getDepth() });
this.showChildView('slider', sliderView);
var firstRegion = this.getRegion('firstRegion');
var foobar = firstRegion.$el.nestedSortable({
this.getRegion('mainline').$el.nestedSortable({
placeholder: 'placeholder',
forcePlaceholderSize: true,
helper: 'clone',
......@@ -1244,9 +1251,15 @@ window.W = window.W || {};
},
val: function (level) {
state.expandLevel = level;
this.$('[data-selected="true"]').attr('data-selected', false);
this.$('[data-value="' + level + '"]').attr('data-selected', true);
this.trigger('level:change', level);
},
onRender: function () {
this.$('[data-selected="true"]').attr('data-selected', false);
this.$('[data-value="' + state.expandLevel + '"]').attr('data-selected', true);
}
});
......@@ -1304,7 +1317,7 @@ window.W = window.W || {};
childView: W.ListItemView,
initialize: function (options) {
this.listenTo(this.collection, 'sync', this.render);
// this.listenTo(this.collection, 'sync', this.render);
},
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment