mirror of
https://github.com/wassname/HackFlowy.git
synced 2026-06-27 16:00:04 +08:00
Merge branch 'master' into gh-pages
Conflicts: javascripts/vendor/custom.modernizr.js javascripts/vendor/zepto.js mockup.html stylesheets/normalize.css
This commit is contained in:
+23
-20
@@ -20,9 +20,10 @@ define(
|
||||
// The recursive tree view. Ref:http://jsfiddle.net/wassname/zf61mLvh/2/
|
||||
var TaskView = Backbone.Marionette.CompositeView.extend({
|
||||
|
||||
template: _.template(taskTemplate), //'#task-view-template',
|
||||
template: _.template(taskTemplate),
|
||||
tagName: 'ul',
|
||||
className: "shift",
|
||||
className: "task-view",
|
||||
viewComparator: List.prototype.comporator,
|
||||
childView: TaskView,
|
||||
childViewContainer: '.children',
|
||||
childViewOptions: {
|
||||
@@ -50,38 +51,42 @@ define(
|
||||
'click .complete:first': 'markComplete',
|
||||
'click .uncomplete:first': 'unmarkComlete',
|
||||
'click .note:first': 'addNote',
|
||||
'click .mouse-tip:first': 'foldChildren',
|
||||
'click .fold-button:first': 'foldChildren',
|
||||
'click .fold:first': 'foldChildren',
|
||||
'click .destroy:first': 'destroy',
|
||||
// custom events
|
||||
'focus': 'this.model.focusOnView',
|
||||
|
||||
},
|
||||
|
||||
collectionEvents: {},
|
||||
collectionEvents: {
|
||||
},
|
||||
|
||||
childEvents: {},
|
||||
|
||||
initialize: function (options) {
|
||||
var task = this;
|
||||
|
||||
// options
|
||||
if (!('reorderOnSort' in options)) {
|
||||
options.reorderOnSort = true;
|
||||
}
|
||||
|
||||
// backlink
|
||||
this.model.view = this;
|
||||
|
||||
var children = Tasks.filter(
|
||||
var children = pageView.collection.filter(
|
||||
function (child, index, collection) {
|
||||
return child.get('parentId') === this.model.id;
|
||||
}, this);
|
||||
this.collection = new List(children);
|
||||
|
||||
// there is probobly a better way to do this
|
||||
if (this.isEmpty()){
|
||||
this.$el.addClass('empty');
|
||||
}
|
||||
|
||||
// events
|
||||
this.listenTo(this.model, 'change', this.render);
|
||||
this.listenTo(this.model, 'destroy', this.remove);
|
||||
// refresh ui hashes after children are rendered
|
||||
this.listenTo(this, 'render:collection', this.bindUIElements);
|
||||
// custom event
|
||||
this.listenTo(this, 'childview:rerender', this.render);
|
||||
this.listenTo(this, 'focus', this.model.focusOnView);
|
||||
|
||||
// updates from server
|
||||
@@ -113,9 +118,9 @@ define(
|
||||
|
||||
/** Get the parent view or root view **/
|
||||
getParentView: function () {
|
||||
var parent = Tasks.get(this.model.get('parentId'));
|
||||
var parent = pageView.collection.get(this.model.get('parentId'));
|
||||
if (parent) return parent.view;
|
||||
else return listView;
|
||||
else return pageView.listView;
|
||||
},
|
||||
|
||||
/** Update parentId when added to collection **/
|
||||
@@ -126,7 +131,7 @@ define(
|
||||
|
||||
/** Focus on the next visible element down despite list level **/
|
||||
focusOnPrev: function () {
|
||||
var all = listView.$el.find('ul:visible');
|
||||
var all = pageView.listView.$el.find('ul:visible');
|
||||
var prev = $(all[all.index(this.$el) - 1]);
|
||||
if (prev.length){
|
||||
prev.find('input:first').focus();
|
||||
@@ -135,7 +140,7 @@ define(
|
||||
},
|
||||
|
||||
focusOnNext: function () {
|
||||
var all = listView.$el.find('ul:visible');
|
||||
var all = pageView.listView.$el.find('ul:visible');
|
||||
var next = $(all[all.index(this.$el) + 1]);
|
||||
if (next)
|
||||
next.find('input:first').focus();
|
||||
@@ -169,13 +174,11 @@ define(
|
||||
// move down list by swapping priority with next sibling
|
||||
e.preventDefault();
|
||||
this.getParentView().collection.moveDown(this.model);
|
||||
this.trigger('rerender');
|
||||
this.model.focusOnView();
|
||||
} else if (e.ctrlKey && e.keyCode == constants.UP_ARROW) {
|
||||
// move up the list
|
||||
e.preventDefault();
|
||||
this.getParentView().collection.moveUp(this.model);
|
||||
this.trigger('rerender');
|
||||
this.model.focusOnView();
|
||||
} else if (e.keyCode == constants.DOWN_ARROW) {
|
||||
this.focusOnNext();
|
||||
@@ -188,7 +191,7 @@ define(
|
||||
if (parentId===0){
|
||||
|
||||
} else if (parentId){
|
||||
parentModel = Tasks.get(parentId);
|
||||
parentModel = pageView.collection.get(parentId);
|
||||
this.getParentView().collection.remove(this.model);
|
||||
var index = parentModel.view.getParentView().collection.indexOf(parentModel);
|
||||
if (index<0) index=this.getParentView().collection.length-1;
|
||||
@@ -203,7 +206,7 @@ define(
|
||||
var prevSibling = this.$el.prev('ul');
|
||||
if (prevSibling.length) {
|
||||
var prevSibId = prevSibling.find('input:first').data('id');
|
||||
var prevSibView =Tasks.get(prevSibId).view;
|
||||
var prevSibView =pageView.collection.get(prevSibId).view;
|
||||
this.getParentView().collection.remove(this.model);
|
||||
prevSibView.collection.add(this.model);
|
||||
this.model.focusOnView();
|
||||
@@ -269,7 +272,7 @@ define(
|
||||
|
||||
var index= this.getParentView().collection.indexOf(this.model);
|
||||
|
||||
var task = Tasks.add({parentId: this.model.get('parentId')});
|
||||
var task = pageView.collection.add({parentId: this.model.get('parentId')});
|
||||
task.save();
|
||||
if (index>=0)
|
||||
this.getParentView().collection.add(task, {at:index+1});
|
||||
|
||||
Reference in New Issue
Block a user