mirror of
https://github.com/wassname/HackFlowy.git
synced 2026-08-12 11:40:31 +08:00
isfolded column, uuid instead of int for id
This commit is contained in:
@@ -31,48 +31,6 @@ define(
|
||||
initialize: function () {
|
||||
},
|
||||
|
||||
|
||||
/** Get root id for the displayed list from the url hash or 0 **/
|
||||
// getRootId: function(){
|
||||
// var hash = window.location.hash.slice(1);
|
||||
// return hash ? hash: 0;
|
||||
//
|
||||
// },
|
||||
|
||||
// /** Called when window location hash changes **/
|
||||
// changeRootId: function(){
|
||||
// this.collection.remove(this.collection.models);
|
||||
// this.collection.add(pageView.collection.filter(this.filterDirectChildren,this));
|
||||
// this.updateBreadCrumbs();
|
||||
// },
|
||||
|
||||
// updateBreadCrumbs: function(){
|
||||
// var rootId = this.getRootId();
|
||||
// if (rootId){
|
||||
// var current = Tasks.get(rootId);
|
||||
// var breadCrumbs = _.template('<a href="#<%= id %>"><%= content %></a>')(current.attributes);
|
||||
// var depth=0;
|
||||
// while (current.get('parentId') && depth<100){
|
||||
// depth++;
|
||||
// current = Tasks.get(current.get('parentId'));
|
||||
// breadCrumbs=_.template('<a href="#<%= id %>"><%= content %></a> > ')(current.attributes)+breadCrumbs;
|
||||
// }
|
||||
// if (depth>=100) console.error('Max depth exceeded while making breadCrumbs');
|
||||
// breadCrumbs='<a href="#">Home</a> > '+breadCrumbs;
|
||||
// $('#task-breadcrumbs').append(breadCrumbs);
|
||||
//
|
||||
// }
|
||||
// },
|
||||
|
||||
// Only show direct children
|
||||
// filterDirectChildren: function (child, index, collection) {
|
||||
// var rootId = this.getRootId();
|
||||
// if (rootId)
|
||||
// return child.get('id') == rootId;
|
||||
// else
|
||||
// return child.get('parentId') == rootId;
|
||||
// },
|
||||
|
||||
/** This is the root view in the tree **/
|
||||
getParentView: function () {
|
||||
return this;
|
||||
|
||||
@@ -3,9 +3,10 @@ define(
|
||||
'backbone',
|
||||
'marionette',
|
||||
'views/list',
|
||||
'data/demo',
|
||||
'text!data/demo.json',
|
||||
'models/task',
|
||||
'collections/list'
|
||||
'collections/list',
|
||||
'util/constants',
|
||||
],
|
||||
|
||||
function(
|
||||
@@ -15,7 +16,8 @@ Marionette,
|
||||
ListView,
|
||||
demoData,
|
||||
Task,
|
||||
List
|
||||
List,
|
||||
constants
|
||||
) {
|
||||
|
||||
var PageView = Marionette.View.extend({
|
||||
@@ -87,7 +89,7 @@ List
|
||||
return hash;
|
||||
else if (hash)
|
||||
window.location.hash='';
|
||||
return 0;
|
||||
return constants.ROOT_PARENT_ID;
|
||||
},
|
||||
|
||||
/** Called when window location hash changes **/
|
||||
@@ -101,23 +103,24 @@ List
|
||||
// Only show direct children
|
||||
filterDirectChildren: function (child, index, collection) {
|
||||
var rootId = this.getRootId();
|
||||
if (rootId)
|
||||
return child.get('id') == rootId;
|
||||
if (rootId === constants.ROOT_PARENT_ID)
|
||||
return child.get('parentId') === rootId;
|
||||
else
|
||||
return child.get('parentId') == rootId;
|
||||
return child.get('id') == rootId;
|
||||
},
|
||||
|
||||
updateBreadCrumbs: function(){
|
||||
var rootId = this.getRootId();
|
||||
this.$('#task-breadcrumbs').empty();
|
||||
if (rootId){
|
||||
if (rootId!==constants.ROOT_PARENT_ID){
|
||||
var current = this.collection.get(rootId);
|
||||
var breadCrumbs = '';//_.template('<a href="#<%= id %>"><%= content %></a>')(current.attributes);
|
||||
var depth=0;
|
||||
while (current.get('parentId') && depth<100){
|
||||
while (current && current.get('parentId') && depth<100){
|
||||
depth++;
|
||||
current = this.collection.get(current.get('parentId'));
|
||||
breadCrumbs=_.template('<a href="#<%= id %>"><%= content %></a> > ')(current.attributes)+breadCrumbs;
|
||||
if (current)
|
||||
breadCrumbs=_.template('<a href="#<%= id %>"><%= content %></a> > ')(current.attributes)+breadCrumbs;
|
||||
}
|
||||
if (depth>=100) console.error('Max depth exceeded while making breadCrumbs');
|
||||
breadCrumbs='<a href="#">Home</a> > '+breadCrumbs;
|
||||
|
||||
@@ -5,7 +5,7 @@ define(
|
||||
'collections/list',
|
||||
'util/constants',
|
||||
'text!../../templates/task.html',
|
||||
'marionette',
|
||||
'marionette'
|
||||
],
|
||||
|
||||
function (
|
||||
@@ -53,6 +53,7 @@ define(
|
||||
'click .note:first': 'addNote',
|
||||
'click .fold-button:first': 'foldChildren',
|
||||
'click .fold:first': 'foldChildren',
|
||||
// TODO make this destroy children too
|
||||
'click .destroy:first': 'destroy',
|
||||
// custom events
|
||||
'focus': 'this.model.focusOnView',
|
||||
@@ -70,6 +71,7 @@ define(
|
||||
// backlink
|
||||
this.model.view = this;
|
||||
|
||||
// get only direct children from all tasks in pageView.collection
|
||||
var children = pageView.collection.filter(
|
||||
function (child, index, collection) {
|
||||
return child.get('parentId') === this.model.id;
|
||||
@@ -98,8 +100,6 @@ define(
|
||||
'content': data.content,
|
||||
'isCompleted': data.isCompleted
|
||||
});
|
||||
} else {
|
||||
console.error("task.model.id != data.id", task.model.id, data.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -159,8 +159,8 @@ define(
|
||||
if (this.ui.input.val().length < 2 && this.$('.children>ul').length===0) {
|
||||
e.preventDefault();
|
||||
prev = this.focusOnPrev();
|
||||
this.destroy();
|
||||
this.model.destroy();
|
||||
this.destroy();
|
||||
// set the cursor to the end of the previous input
|
||||
prev.find('input:first').focus();
|
||||
var input = prev.find('input:first')[0];
|
||||
@@ -230,9 +230,8 @@ define(
|
||||
/** Finish editing an item **/
|
||||
close: function () {
|
||||
var value = this.$('.edit:first').val().trim();
|
||||
this.model.save({
|
||||
content: value
|
||||
});
|
||||
if (this.model.get('content')!=value)
|
||||
this.model.save({content: value});
|
||||
this.$el.removeClass('editing');
|
||||
},
|
||||
|
||||
@@ -266,32 +265,23 @@ define(
|
||||
|
||||
/** Add a new blank note below this **/
|
||||
addNote: function () {
|
||||
var currentId = this.ui.input.data('id') || 0;
|
||||
// var currentId = this.ui.input.data('id') || 0;
|
||||
parentId = this.ui.input.data('parent-id');
|
||||
|
||||
|
||||
var index= this.getParentView().collection.indexOf(this.model);
|
||||
|
||||
var task = pageView.collection.add({parentId: this.model.get('parentId')});
|
||||
task.save();
|
||||
if (index>=0)
|
||||
this.getParentView().collection.add(task, {at:index+1});
|
||||
else
|
||||
this.getParentView().collection.add(task);
|
||||
console.log(index);
|
||||
this.ui.input.blur();
|
||||
task.view.ui.input.focus();
|
||||
this.$('input:first').blur();
|
||||
task.focusOnView();
|
||||
},
|
||||
|
||||
/** Fold children of the clicked element */
|
||||
foldChildren: function () {
|
||||
if (this.ui.children.length > 0) {
|
||||
this.ui.children.toggle();
|
||||
this.$el.find('li:first').toggleClass('folded');
|
||||
} else {
|
||||
this.ui.children.show();
|
||||
this.$el.find('li:first').removeClass('folded');
|
||||
}
|
||||
var folded = this.$el.find('li:first').hasClass('folded');
|
||||
this.model.save({isFolded: !folded});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user