From 2d5601f920b1a23ab743c8cb8a39de7590e03f61 Mon Sep 17 00:00:00 2001 From: pahaz Date: Mon, 12 Nov 2012 00:55:58 +0600 Subject: [PATCH 1/9] init git --- .gitignore | 1 + .gitmodules | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62c8935 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..14dbec6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "oop"] + path = oop + url = https://github.com/pahaz/dz-4-oop.git +[submodule "todo"] + path = todo + url = https://github.com/addyosmani/todomvc.git From 9cb38f97430dcc04b0ea9f6f9115de742d5a8090 Mon Sep 17 00:00:00 2001 From: pahaz Date: Mon, 12 Nov 2012 01:04:25 +0600 Subject: [PATCH 2/9] init submodules --- oop | 1 + todo | 1 + 2 files changed, 2 insertions(+) create mode 160000 oop create mode 160000 todo diff --git a/oop b/oop new file mode 160000 index 0000000..861d093 --- /dev/null +++ b/oop @@ -0,0 +1 @@ +Subproject commit 861d093af2fd2645d5629b88b2146fbfd216f1d3 diff --git a/todo b/todo new file mode 160000 index 0000000..c6027e6 --- /dev/null +++ b/todo @@ -0,0 +1 @@ +Subproject commit c6027e641c4b40ac37be517edda514711d600774 From a37286731fc13c1031fac9c1e49d521db1effe9c Mon Sep 17 00:00:00 2001 From: pahaz Date: Mon, 12 Nov 2012 01:13:40 +0600 Subject: [PATCH 3/9] init work html and styles --- index.html | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 75 +++++++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100644 index.html create mode 100644 index.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..6a3c85b --- /dev/null +++ b/index.html @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + Yo! + + + +
+
+ +
+
    +
  • + +
    +
    Name: pewpew
    +
    Start: 18.8.2005 12:00
    +
    End: 18.8.2005 12:30
    +
    +
  • +
+
+
+
+ +
+ +​ + + + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..9b6d3d5 --- /dev/null +++ b/index.js @@ -0,0 +1,75 @@ +/** + * Created with PyCharm. + * User: stribog + * Date: 11.11.12 + * Time: 22:08 + * To change this template use File | Settings | File Templates. + */ + +var button = document.getElementById('add-button'); +var dom_list_parent = document.getElementById('todo-list'); + +var PaintEventsTemplate = _.template("\ +<% collection.each(function(event) { %> \ +
  • \ + <% if (event.get('go')) { %> \ + \ + <% } %> \ +
    \ +
    <%- event.get('title') %>
    \ +
    Start: <%- event.get('start_time').toLocaleDateString() %>
    \ +
    End: <%- event.get('end_time').toLocaleDateString() %>
    \ +
    \ +
  • \ +<% }); %>"); + +var collection = new EventsCollection([ + createNewEvent(new Date(2000, 10, 1), new Date(2000, 11, 1), "First", true), + createNewEvent(new Date(2005, 5, 1), new Date(2006, 1, 1), "Second"), + createNewEvent(new Date(2001, 10, 1), new Date(2006, 10, 1), "Looooong event", true), + createNewEvent(new Date(1991, 5, 1), new Date(2000, 1, 20), "OoOOOoold event"), + createNewEvent(new Date(2007, 3, 11), new Date(2008, 1, 5), "from 2007 to 2008", true), + createNewEvent(new Date(2000, 5, 12), new Date(2020, 8, 17), "from 2000 To futureeeee"), + createNewEvent(new Date(2013, 5, 12), new Date(2017, 1, 27), "Futureeeee", true), + createNewEvent(new Date(2006, 10, 1), new Date(2008, 11, 1), "Firth") +]); +var current_collection = collection; + +function PaintEvents(collection) { + dom_list_parent.innerHTML = PaintEventsTemplate({'collection': collection}); +} + + +// Events + +button.addEventListener('click', function () { + +}); + + + + + + + + + + + + + + + + + + + + + +function TestIndex() { + var a = PaintEventsTemplate({'collection': collection}); + //console.log(a.length); + ok('Template', a.length, 903); + +} +TestIndex(); \ No newline at end of file From f9373bf3bae559a90d59cdaea41895b3b8e35a41 Mon Sep 17 00:00:00 2001 From: pahaz Date: Mon, 12 Nov 2012 01:45:09 +0600 Subject: [PATCH 4/9] fix submodules --- oop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oop b/oop index 861d093..124974c 160000 --- a/oop +++ b/oop @@ -1 +1 @@ -Subproject commit 861d093af2fd2645d5629b88b2146fbfd216f1d3 +Subproject commit 124974ca53663cee20e397c763dde35e69d6d394 From 1ddf52f510d84b3a467f7df77800bda4bbfd25c5 Mon Sep 17 00:00:00 2001 From: pahaz Date: Mon, 12 Nov 2012 02:45:00 +0600 Subject: [PATCH 5/9] Find strange error. --- index.html | 4 +- index.js | 129 +++++++++++++++++++++++++++-------------------------- 2 files changed, 67 insertions(+), 66 deletions(-) diff --git a/index.html b/index.html index 6a3c85b..fab3b4f 100644 --- a/index.html +++ b/index.html @@ -53,11 +53,11 @@

    Events


    diff --git a/index.js b/index.js index 9b6d3d5..a14a2a3 100644 --- a/index.js +++ b/index.js @@ -6,70 +6,71 @@ * To change this template use File | Settings | File Templates. */ -var button = document.getElementById('add-button'); -var dom_list_parent = document.getElementById('todo-list'); - -var PaintEventsTemplate = _.template("\ -<% collection.each(function(event) { %> \ -
  • \ - <% if (event.get('go')) { %> \ - \ - <% } %> \ -
    \ -
    <%- event.get('title') %>
    \ -
    Start: <%- event.get('start_time').toLocaleDateString() %>
    \ -
    End: <%- event.get('end_time').toLocaleDateString() %>
    \ -
    \ -
  • \ -<% }); %>"); - -var collection = new EventsCollection([ - createNewEvent(new Date(2000, 10, 1), new Date(2000, 11, 1), "First", true), - createNewEvent(new Date(2005, 5, 1), new Date(2006, 1, 1), "Second"), - createNewEvent(new Date(2001, 10, 1), new Date(2006, 10, 1), "Looooong event", true), - createNewEvent(new Date(1991, 5, 1), new Date(2000, 1, 20), "OoOOOoold event"), - createNewEvent(new Date(2007, 3, 11), new Date(2008, 1, 5), "from 2007 to 2008", true), - createNewEvent(new Date(2000, 5, 12), new Date(2020, 8, 17), "from 2000 To futureeeee"), - createNewEvent(new Date(2013, 5, 12), new Date(2017, 1, 27), "Futureeeee", true), - createNewEvent(new Date(2006, 10, 1), new Date(2008, 11, 1), "Firth") -]); -var current_collection = collection; - -function PaintEvents(collection) { - dom_list_parent.innerHTML = PaintEventsTemplate({'collection': collection}); +var app = function () {}; +app.prototype.init = function () { + var self = this; + this.action = document.getElementById('add-button'); + this.render = document.getElementById('todo-list'); + this.inputs = { + 'title': document.getElementById('new-todo'), + 'start_time': document.getElementById('js-start_time'), + 'end_time': document.getElementById('js-end_time') + }; + this.full_collection = new EventsCollection([ + createNewEvent(new Date(2000, 10, 1), new Date(2000, 11, 1), "First", true), + createNewEvent(new Date(2005, 5, 1), new Date(2006, 1, 1), "Second"), + createNewEvent(new Date(2001, 10, 1), new Date(2006, 10, 1), "Looooong event", true), + createNewEvent(new Date(1991, 5, 1), new Date(2000, 1, 20), "OoOOOoold event"), + createNewEvent(new Date(2007, 3, 11), new Date(2008, 1, 5), "from 2007 to 2008", true), + createNewEvent(new Date(2000, 5, 12), new Date(2020, 8, 17), "from 2000 To futureeeee"), + createNewEvent(new Date(2013, 5, 12), new Date(2017, 1, 27), "Futureeeee", true), + createNewEvent(new Date(2006, 10, 1), new Date(2008, 11, 1), "Firth") + ]); + this.current_collection = this.full_collection; + + this.template = _.template("\ + <% collection.each(function(event) { %> \ +
  • \ + <% if (event.get('go')) { %> \ + \ + <% } %> \ +
    \ +
    <%- event.get('title') %>
    \ +
    Start: <%- event.get('start_time').toLocaleDateString() %>
    \ +
    End: <%- event.get('end_time').toLocaleDateString() %>
    \ +
    \ +
  • \ + <% }); %>"); + + this.action.addEventListener('click', function (event) { + self.action_click(event); + }); + // TODO: add events for filters; +}; +app.prototype.action_click = function (event) { // WTF: this is WINDOW !!! + var info = {}; + _.each(this.inputs, function(num, key) { + info[key] = num.value; + }); + + try { + var new_event = new this.full_collection.model(info); + this.full_collection.add(new_event); + this.change_current_collection(); + } catch (e) { + console.log("errrore"); + } +}; +app.prototype.change_current_collection = function () { + this.current_collection = this.full_collection; + // TODO: filters detect; + this.paint(); +}; +app.prototype.paint = function () { + this.render.innerHTML = this.template({'collection': this.current_collection}); } +var application = new app(); +application.init(); +application.paint(); -// Events - -button.addEventListener('click', function () { - -}); - - - - - - - - - - - - - - - - - - - - - -function TestIndex() { - var a = PaintEventsTemplate({'collection': collection}); - //console.log(a.length); - ok('Template', a.length, 903); - -} -TestIndex(); \ No newline at end of file From 94a8964c2df4e229d7dd1f8ee8f9c55a080b6267 Mon Sep 17 00:00:00 2001 From: pahaz Date: Tue, 27 Nov 2012 02:46:26 +0600 Subject: [PATCH 6/9] Add create event button --- index.html | 12 ++++++------ index.js | 20 ++++++++++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/index.html b/index.html index fab3b4f..e2a61a1 100644 --- a/index.html +++ b/index.html @@ -71,14 +71,14 @@

    Events


    - - + +
    Order by
    - - - - + + + +
    diff --git a/index.js b/index.js index a14a2a3..82c5330 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,6 @@ var app = function () {}; app.prototype.init = function () { var self = this; - this.action = document.getElementById('add-button'); this.render = document.getElementById('todo-list'); this.inputs = { 'title': document.getElementById('new-todo'), @@ -42,9 +41,21 @@ app.prototype.init = function () { \ <% }); %>"); + this.action = document.getElementById('add-button'); this.action.addEventListener('click', function (event) { self.action_click(event); + event.preventDefault(); + }); + + var listeners = document.querySelectorAll('.js-filters'); + _.each(listeners, function(listener){ + listener.addEventListener('change', this.change_current_collection); }); + + this.filters = function () { + var my = document.getElementById('filter_my').checked; + var future = document.getElementById('filter_future').checked; + }; // TODO: add events for filters; }; app.prototype.action_click = function (event) { // WTF: this is WINDOW !!! @@ -54,11 +65,12 @@ app.prototype.action_click = function (event) { // WTF: this is WINDOW !!! }); try { - var new_event = new this.full_collection.model(info); + var model_class = this.full_collection.model; + var new_event = new model_class(info); this.full_collection.add(new_event); this.change_current_collection(); } catch (e) { - console.log("errrore"); + alert(e.message); } }; app.prototype.change_current_collection = function () { @@ -68,7 +80,7 @@ app.prototype.change_current_collection = function () { }; app.prototype.paint = function () { this.render.innerHTML = this.template({'collection': this.current_collection}); -} +}; var application = new app(); application.init(); From b3a20d3e97a894a693acdf1529607ed3837b1daa Mon Sep 17 00:00:00 2001 From: pahaz Date: Tue, 27 Nov 2012 03:21:44 +0600 Subject: [PATCH 7/9] complete --- index.html | 8 +++--- index.js | 71 ++++++++++++++++++++++++++++++++++++++++++++---------- oop | 2 +- 3 files changed, 63 insertions(+), 18 deletions(-) diff --git a/index.html b/index.html index e2a61a1..3635527 100644 --- a/index.html +++ b/index.html @@ -75,10 +75,10 @@

    Events

    Order by
    - - - - + + + +
    diff --git a/index.js b/index.js index 82c5330..33b3b4a 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,24 @@ /** * Created with PyCharm. - * User: stribog + * User: pahaz * Date: 11.11.12 * Time: 22:08 * To change this template use File | Settings | File Templates. */ +/** + * Application Event. + * + * @constructor + * @this {app} + */ var app = function () {}; + +/** + * Application initialization. + * + * @this {app} + */ app.prototype.init = function () { var self = this; this.render = document.getElementById('todo-list'); @@ -48,16 +60,17 @@ app.prototype.init = function () { }); var listeners = document.querySelectorAll('.js-filters'); - _.each(listeners, function(listener){ - listener.addEventListener('change', this.change_current_collection); + var self = this; + _.each(listeners, function(listener) { + listener.addEventListener('change', self.change_current_collection.bind(self)); }); - - this.filters = function () { - var my = document.getElementById('filter_my').checked; - var future = document.getElementById('filter_future').checked; - }; - // TODO: add events for filters; }; + +/** + * Application click action listener. + * + * @this {app} + */ app.prototype.action_click = function (event) { // WTF: this is WINDOW !!! var info = {}; _.each(this.inputs, function(num, key) { @@ -68,16 +81,49 @@ app.prototype.action_click = function (event) { // WTF: this is WINDOW !!! var model_class = this.full_collection.model; var new_event = new model_class(info); this.full_collection.add(new_event); - this.change_current_collection(); + this.change_current_collection(event); } catch (e) { alert(e.message); } }; -app.prototype.change_current_collection = function () { + +/** + * Application change collection listener. + * + * @this {app} + */ +app.prototype.change_current_collection = function (event) { this.current_collection = this.full_collection; - // TODO: filters detect; + + // TODO: optimization; + var my = document.getElementById('filter_my').checked; + var future = document.getElementById('filter_future').checked; + var sort = false; + + if (document.querySelector('input[name="sort"]:checked') !== null) { + sort = document.querySelector('input[name="sort"]:checked').value; + } + + var tmp_collection = this.current_collection; + if (my) { + tmp_collection = tmp_collection.my_events(); + } + if (future) { + tmp_collection = tmp_collection.start_after(new Date()); + } + if (sort) { + tmp_collection = tmp_collection.sortBy(function (model) { return model.get(sort); }); + } + + this.current_collection = tmp_collection; this.paint(); }; + +/** + * Render current collection. + * + * @this {app} + */ app.prototype.paint = function () { this.render.innerHTML = this.template({'collection': this.current_collection}); }; @@ -85,4 +131,3 @@ app.prototype.paint = function () { var application = new app(); application.init(); application.paint(); - diff --git a/oop b/oop index 124974c..f5ac4c4 160000 --- a/oop +++ b/oop @@ -1 +1 @@ -Subproject commit 124974ca53663cee20e397c763dde35e69d6d394 +Subproject commit f5ac4c4bbcf79e5efb2f68299c0b312da91a75cc From 487dabd6170ef4a5f5b55e38dade398e67df7e17 Mon Sep 17 00:00:00 2001 From: pahaz Date: Tue, 27 Nov 2012 03:44:06 +0600 Subject: [PATCH 8/9] add new function logic for ajax --- index.js | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 33b3b4a..6caf4f3 100644 --- a/index.js +++ b/index.js @@ -27,16 +27,8 @@ app.prototype.init = function () { 'start_time': document.getElementById('js-start_time'), 'end_time': document.getElementById('js-end_time') }; - this.full_collection = new EventsCollection([ - createNewEvent(new Date(2000, 10, 1), new Date(2000, 11, 1), "First", true), - createNewEvent(new Date(2005, 5, 1), new Date(2006, 1, 1), "Second"), - createNewEvent(new Date(2001, 10, 1), new Date(2006, 10, 1), "Looooong event", true), - createNewEvent(new Date(1991, 5, 1), new Date(2000, 1, 20), "OoOOOoold event"), - createNewEvent(new Date(2007, 3, 11), new Date(2008, 1, 5), "from 2007 to 2008", true), - createNewEvent(new Date(2000, 5, 12), new Date(2020, 8, 17), "from 2000 To futureeeee"), - createNewEvent(new Date(2013, 5, 12), new Date(2017, 1, 27), "Futureeeee", true), - createNewEvent(new Date(2006, 10, 1), new Date(2008, 11, 1), "Firth") - ]); + + this.full_collection = new EventsCollection(this.load()); this.current_collection = this.full_collection; this.template = _.template("\ @@ -66,6 +58,24 @@ app.prototype.init = function () { }); }; +/** + * Load initial collection data. + * + * @this {app} + */ +app.prototype.load = function () { + return [ + createNewEvent(new Date(2000, 10, 1), new Date(2000, 11, 1), "First", true), + createNewEvent(new Date(2005, 5, 1), new Date(2006, 1, 1), "Second"), + createNewEvent(new Date(2001, 10, 1), new Date(2006, 10, 1), "Looooong event", true), + createNewEvent(new Date(1991, 5, 1), new Date(2000, 1, 20), "OoOOOoold event"), + createNewEvent(new Date(2007, 3, 11), new Date(2008, 1, 5), "from 2007 to 2008", true), + createNewEvent(new Date(2000, 5, 12), new Date(2020, 8, 17), "from 2000 To futureeeee"), + createNewEvent(new Date(2013, 5, 12), new Date(2017, 1, 27), "Futureeeee", true), + createNewEvent(new Date(2006, 10, 1), new Date(2008, 11, 1), "Firth") + ]; +}; + /** * Application click action listener. * @@ -82,11 +92,21 @@ app.prototype.action_click = function (event) { // WTF: this is WINDOW !!! var new_event = new model_class(info); this.full_collection.add(new_event); this.change_current_collection(event); + this.save(); } catch (e) { alert(e.message); } }; +/** + * Save collection data. + * + * @this {app} + */ +app.prototype.save = function() { + +}; + /** * Application change collection listener. * From d1dbb0e3de3faf12bc8d064b5ab27526fa52bf6d Mon Sep 17 00:00:00 2001 From: pahaz Date: Tue, 27 Nov 2012 03:45:07 +0600 Subject: [PATCH 9/9] comment init app --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 6caf4f3..d338d2d 100644 --- a/index.js +++ b/index.js @@ -148,6 +148,8 @@ app.prototype.paint = function () { this.render.innerHTML = this.template({'collection': this.current_collection}); }; +/* var application = new app(); application.init(); application.paint(); +*/ \ No newline at end of file