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 diff --git a/index.html b/index.html new file mode 100644 index 0000000..3635527 --- /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..d338d2d --- /dev/null +++ b/index.js @@ -0,0 +1,155 @@ +/** + * Created with PyCharm. + * 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'); + 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(this.load()); + 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 = document.getElementById('add-button'); + this.action.addEventListener('click', function (event) { + self.action_click(event); + event.preventDefault(); + }); + + var listeners = document.querySelectorAll('.js-filters'); + var self = this; + _.each(listeners, function(listener) { + listener.addEventListener('change', self.change_current_collection.bind(self)); + }); +}; + +/** + * 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. + * + * @this {app} + */ +app.prototype.action_click = function (event) { // WTF: this is WINDOW !!! + var info = {}; + _.each(this.inputs, function(num, key) { + info[key] = num.value; + }); + + try { + var model_class = this.full_collection.model; + 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. + * + * @this {app} + */ +app.prototype.change_current_collection = function (event) { + this.current_collection = this.full_collection; + + // 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}); +}; + +/* +var application = new app(); +application.init(); +application.paint(); +*/ \ No newline at end of file diff --git a/oop b/oop new file mode 160000 index 0000000..f5ac4c4 --- /dev/null +++ b/oop @@ -0,0 +1 @@ +Subproject commit f5ac4c4bbcf79e5efb2f68299c0b312da91a75cc diff --git a/todo b/todo new file mode 160000 index 0000000..c6027e6 --- /dev/null +++ b/todo @@ -0,0 +1 @@ +Subproject commit c6027e641c4b40ac37be517edda514711d600774