mirror of
https://github.com/wassname/HackFlowy.git
synced 2026-06-30 16:30:07 +08:00
Merge branch 'master' into gh-pages
Conflicts: javascripts/app.js
This commit is contained in:
@@ -5,6 +5,8 @@ require.config({
|
||||
jquery: '../bower_components/jquery/dist/jquery.min',
|
||||
lodash: "../bower_components/lodash/dist/lodash.min",
|
||||
backbone: '../bower_components/backbone/backbone-min',
|
||||
localforage: '../bower_components/localforage/dist/localforage',
|
||||
localforagebackbone: '../bower_components/localforage-backbone/dist/localforage.backbone',
|
||||
modernizr: "vendor/custom.modernizr",
|
||||
socket: "../bower_components/socket.io-client/socket.io",
|
||||
text: '../bower_components/text/text',
|
||||
|
||||
@@ -1,21 +1,35 @@
|
||||
define(
|
||||
[
|
||||
'backbone',
|
||||
'models/task'
|
||||
'models/task',
|
||||
'localforage',
|
||||
'localforagebackbone'
|
||||
],
|
||||
|
||||
function(
|
||||
Backbone,
|
||||
Task
|
||||
Task,
|
||||
localforage,
|
||||
localforageBackbone
|
||||
) {
|
||||
|
||||
var List = Backbone.Collection.extend({
|
||||
|
||||
|
||||
model: Task,
|
||||
offlineSync: Backbone.localforage.sync("tasks"),
|
||||
/** switches sync between server and local databases **/
|
||||
sync: function(){
|
||||
if (window.hackflowyOffline)
|
||||
return this.offlineSync.apply(this, arguments);
|
||||
else
|
||||
return Backbone.sync.apply(this, arguments);
|
||||
},
|
||||
|
||||
url: '/tasks'
|
||||
|
||||
|
||||
});
|
||||
|
||||
return List;
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,13 +1,26 @@
|
||||
define(
|
||||
['backbone'
|
||||
['backbone',
|
||||
'localforage',
|
||||
'localforagebackbone'
|
||||
],
|
||||
|
||||
function(
|
||||
Backbone
|
||||
Backbone,
|
||||
localforage,
|
||||
localforageBackbone
|
||||
) {
|
||||
|
||||
var TaskModel = Backbone.Model.extend({
|
||||
|
||||
offlineSync: Backbone.localforage.sync('TaskModel'),
|
||||
/** switches sync between server and local databases **/
|
||||
sync: function(){
|
||||
if (window.hackflowyOffline)
|
||||
return this.offlineSync.apply(this,arguments);
|
||||
else
|
||||
return Backbone.sync.apply(this, arguments);
|
||||
},
|
||||
|
||||
defaults: {
|
||||
parentId: 0,
|
||||
content: '',
|
||||
@@ -25,7 +38,7 @@ Backbone
|
||||
//REVERT BACK ON ERROR
|
||||
self.set({'isCompleted':prev_isCompleted});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
+38
-21
@@ -1,17 +1,17 @@
|
||||
var demoData = [{"id":80,"content":"Welcome to HackFlowy!","parentId":0,"isCompleted":false,"priority":0,"createdAt":"2016-01-29T05:44:30.858Z","updatedAt":"2016-01-29T05:44:30.858Z"},{"id":81,"content":"An open-source WorkFlowy clone","parentId":0,"isCompleted":false,"priority":0,"createdAt":"2016-01-29T05:44:30.858Z","updatedAt":"2016-01-29T05:44:30.858Z"},{"id":82,"content":"Built using Backbone + Socket.IO","parentId":0,"isCompleted":false,"priority":0,"createdAt":"2016-01-29T05:44:30.858Z","updatedAt":"2016-01-29T05:44:30.858Z"},{"id":83,"content":"Desyncr pulled this together in a few hours to learn Backbone","parentId":0,"isCompleted":false,"priority":0,"createdAt":"2016-01-29T05:44:30.858Z","updatedAt":"2016-01-29T05:44:30.858Z"},{"id":84,"content":"Feel free to try it out and hack on it","parentId":0,"isCompleted":false,"priority":0,"createdAt":"2016-01-29T05:44:30.858Z","updatedAt":"2016-01-29T05:44:30.858Z"},{"id":85,"content":"Good Luck!","parentId":0,"isCompleted":false,"priority":0,"createdAt":"2016-01-29T05:44:30.858Z","updatedAt":"2016-01-29T05:44:30.858Z"},{"id":86,"content":"P.S","parentId":0,"isCompleted":false,"priority":0,"createdAt":"2016-01-29T05:44:40.978Z","updatedAt":"2016-01-29T05:44:40.978Z"},{"id":88,"content":"It makes sense if you don't think about it; I haven't","parentId":0,"isCompleted":false,"priority":0,"createdAt":"2016-01-29T05:44:58.737Z","updatedAt":"2016-01-29T05:45:50.939Z"},{"id":89,"content":"Make love not war","parentId":88,"isCompleted":false,"priority":0,"createdAt":"2016-01-29T05:45:03.048Z","updatedAt":"2016-01-29T05:45:57.481Z"},{"id":91,"content":"Love can be brought not sold","parentId":88,"isCompleted":false,"priority":0,"createdAt":"2016-01-29T05:45:32.331Z","updatedAt":"2016-01-29T05:46:10.478Z"},{"id":93,"content":"How do I love thee? Let me count the ways - Shakespear","parentId":88,"isCompleted":false,"priority":0,"createdAt":"2016-01-29T05:46:25.119Z","updatedAt":"2016-01-29T05:48:00.604Z"},{"id":95,"content":"Therefore: love can be listed and lists can be loved","parentId":88,"isCompleted":false,"priority":0,"createdAt":"2016-01-29T05:46:38.998Z","updatedAt":"2016-01-29T05:48:22.937Z"},{"id":96,"content":"Conclusion: lists and love should be free","parentId":88,"isCompleted":false,"priority":0,"createdAt":"2016-01-29T05:47:26.684Z","updatedAt":"2016-01-29T05:48:29.796Z"},{"id":97,"content":"But how can our lists be real if our love isnt? - Jaden Smith","parentId":88,"isCompleted":false,"priority":0,"createdAt":"2016-01-29T05:47:46.930Z","updatedAt":"2016-01-29T05:47:46.930Z"}];
|
||||
|
||||
define(
|
||||
['jquery',
|
||||
'backbone',
|
||||
'collections/list',
|
||||
'views/task'
|
||||
'views/task',
|
||||
'data/demo'
|
||||
],
|
||||
|
||||
function (
|
||||
$,
|
||||
Backbone,
|
||||
List,
|
||||
TaskView
|
||||
TaskView,
|
||||
demoData
|
||||
) {
|
||||
|
||||
var ListView = Backbone.View.extend({
|
||||
@@ -24,24 +24,38 @@ define(
|
||||
|
||||
initialize: function () {
|
||||
Tasks = this.collection = new List();
|
||||
var fetchPromise = this.collection.fetch();
|
||||
|
||||
fetchPromise.fail(function (e) {
|
||||
// if the server isn't running load some demo data and a demo warning
|
||||
$('#header').append('<div class="alert-box secondary round">Warning: Running in demo mode, all work will be lost</div>');
|
||||
var data = demoData;
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
Tasks.add(data[i]);
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.listenTo(this.collection, 'add', this.renderTask);
|
||||
|
||||
/** Load demo data and warn users **/
|
||||
function loadDemoData() {
|
||||
for (var i = 0; i < demoData.length; i++) {
|
||||
var task = Tasks.add(demoData[i]);
|
||||
task.save();
|
||||
}
|
||||
}
|
||||
|
||||
function success(data) {
|
||||
// load demo data if the server returns nothing
|
||||
if (data.length === 0)
|
||||
loadDemoData();
|
||||
}
|
||||
|
||||
this.collection.fetch({
|
||||
success: success,
|
||||
error: function () {
|
||||
// switch to localforage database if server isn't present
|
||||
window.hackflowyOffline=true;
|
||||
$('#header').append('<div class="alert-box secondary round">Running in offline mode, data may be lost </div>');
|
||||
Tasks.fetch({
|
||||
success: success
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
render: function (data) {
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
Tasks.add(data[i]);
|
||||
}
|
||||
render: function () {
|
||||
this.collection.each(function (task) {
|
||||
this.renderTask(task);
|
||||
}, this);
|
||||
@@ -55,10 +69,13 @@ define(
|
||||
if (a.model.get('parentId') === 0) {
|
||||
this.$el.append(a.el);
|
||||
} else {
|
||||
var parent = $('*[data-id="' + a.model.get('parentId')+ '"]');
|
||||
if (parent.length===0) {
|
||||
var parent = $('*[data-id="' + a.model.get('parentId') + '"]');
|
||||
if (parent.length === 0) {
|
||||
// TODO deal with loading order
|
||||
console.error("Parent not rendered yet: ", {selector: parent.selector, task: task});
|
||||
console.error("Parent not rendered yet: ", {
|
||||
selector: parent.selector,
|
||||
task: task
|
||||
});
|
||||
this.$el.append(a.el);
|
||||
} else {
|
||||
a.$el.insertBefore(parent.parents('li:first'));
|
||||
|
||||
@@ -127,6 +127,7 @@ define(
|
||||
var value = this.$input.val().trim();
|
||||
if (value === '') {
|
||||
this.model.destroy();
|
||||
// collection.at(this.model.get('id')).destroy();
|
||||
} else {
|
||||
this.model.save({
|
||||
content: value,
|
||||
|
||||
Reference in New Issue
Block a user