Commit efbee5b9 authored by gijs's avatar gijs

Make line state persistent after save

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