From 3037f5926d6c3228fb2b5daf709d5c60fb841e66 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Mon, 9 Sep 2013 13:37:57 +0200 Subject: [PATCH] clean imports and remove old code --- isso/client/admin.js | 41 ------- isso/client/app/api.js | 2 +- isso/client/app/forms.js | 2 +- isso/client/app/isso.js | 9 +- isso/client/app/logging.js | 9 -- isso/client/app/models.js | 10 -- isso/client/client.js | 216 ------------------------------------- isso/client/isso.js | 58 ---------- isso/client/main.js | 6 -- 9 files changed, 3 insertions(+), 350 deletions(-) delete mode 100644 isso/client/admin.js delete mode 100644 isso/client/app/logging.js delete mode 100644 isso/client/app/models.js delete mode 100644 isso/client/client.js delete mode 100644 isso/client/isso.js delete mode 100644 isso/client/main.js diff --git a/isso/client/admin.js b/isso/client/admin.js deleted file mode 100644 index a762267..0000000 --- a/isso/client/admin.js +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright 2012, Martin Zimmermann . All rights reserved. - * License: BSD Style, 2 clauses. See isso/__init__.py. - */ - - -var isso = isso || {}; - - -function initialize() { - - $('div.buttons > a').forEach(function(item) { - - var node = $(item).parent().parent().parent().parent()[0], - id = node.getAttribute("data-id"); - isso.path = node.getAttribute("data-path"); - - if (item.text == 'Approve') { - $(item).on('click', function(event) { - isso.approve(id, function(status, rv) { - $(node).prependTo($('#approved')); - $('.approve', node).remove(); - }); - event.stop(); - }); - } else { - $(item).on('click', function(event) { - if (confirm("RLY?") == true) { - isso.remove(id, function(status, rv) { - $(node).remove() - }); - }; - event.stop(); - }); - }; - }); -}; - - -$.domReady(function() { - initialize(); -}); diff --git a/isso/client/app/api.js b/isso/client/app/api.js index 187c58b..da61266 100644 --- a/isso/client/app/api.js +++ b/isso/client/app/api.js @@ -3,7 +3,7 @@ * License: BSD Style, 2 clauses. See isso/__init__.py. */ -define(["lib/q", "app/models"], function(Q, models) { +define(["lib/q"], function(Q) { // http://stackoverflow.com/questions/17544965/unhandled-rejection-reasons-should-be-empty Q.stopUnhandledRejectionTracking(); diff --git a/isso/client/app/forms.js b/isso/client/app/forms.js index 008e4d6..5b48c88 100644 --- a/isso/client/app/forms.js +++ b/isso/client/app/forms.js @@ -1,4 +1,4 @@ -define(["lib/HTML", "helper/utils"], function(HTML, utils) { +define(["lib/HTML"], function(HTML) { var msgbox = function(defaults) { diff --git a/isso/client/app/isso.js b/isso/client/app/isso.js index 2db4c5f..4463080 100644 --- a/isso/client/app/isso.js +++ b/isso/client/app/isso.js @@ -5,12 +5,7 @@ */ -define(["lib/q", "lib/HTML", "helper/utils", "./api", "./forms", "./logging", "helper/identicons"], function(Q, HTML, utils, api, forms, logging, identicons) { - - var defaults = { - text: "Lorem ipsum ...", author: "Anonymous", - email: "info@example.org", website: "..." - }; +define(["lib/q", "lib/HTML", "helper/utils", "helper/identicons", "./api", "./forms"], function(Q, HTML, utils, identicons, api, forms) { var insert = function(comment, scrollIntoView) { /* @@ -169,8 +164,6 @@ define(["lib/q", "lib/HTML", "helper/utils", "./api", "./forms", "./logging", "h var init = function() { - // console.log(utils.heading()); - var rootmsgbox = forms.msgbox({}); HTML.query("#isso-thread").add("div#isso-root").add(rootmsgbox); rootmsgbox.query("input[type=submit]").addEventListener("click", function(event) { diff --git a/isso/client/app/logging.js b/isso/client/app/logging.js deleted file mode 100644 index ff7e8cb..0000000 --- a/isso/client/app/logging.js +++ /dev/null @@ -1,9 +0,0 @@ -define({ - error: function(err) { - if ("status" in err && "reason" in err) { - console.error("%i: %s", err.status, err.reason) - } else { - console.error(err.stack) - } - } -}) \ No newline at end of file diff --git a/isso/client/app/models.js b/isso/client/app/models.js deleted file mode 100644 index e587d17..0000000 --- a/isso/client/app/models.js +++ /dev/null @@ -1,10 +0,0 @@ -define(function() { - - function Comment(data) { - this.text = data["text"]; - } - - return { - Comment: Comment - } -}); \ No newline at end of file diff --git a/isso/client/client.js b/isso/client/client.js deleted file mode 100644 index 4d465fc..0000000 --- a/isso/client/client.js +++ /dev/null @@ -1,216 +0,0 @@ -/* Copyright 2012, Martin Zimmermann . All rights reserved. - * License: BSD Style, 2 clauses. See isso/__init__.py. - */ - - var isso = isso || {}; - - -function form(id, defaults, func) { - /* - Returns HTML for form and registers submit call. - - Synopsis: `isso_N` is the comment with the id N. `issoform` is a new - form to write an answer to the article or answer to a comment using - `issoform_N` where N is the id to respond to. - - :param id: comment id - :param returnfunc: function, that takes one argument (the HTML to display the form) - :param func: function, when the user submits the form - */ - - var rv = $(brew([ - 'div', {'class': 'issoform', 'id': 'issoform' + (id ? ('_' + id) : '')}, - ['div', - ['input', {'type': 'text', 'name': 'author', 'id': 'author', 'value': defaults.author || "", 'placeholder': "Name"}]], - ['div', - ['input', {'type': 'email', 'name': 'email', 'id': 'email', 'value': defaults.email || "", 'placeholder': "Email"}]], - ['div', - ['input', {'type': 'url', 'name': 'website', 'id': 'website', 'value': defaults.website || "", 'placeholder': "Website"}]], - ['div', - ['textarea', defaults.text || "", {'rows': '10', 'name': 'text', 'id': 'comment', 'placeholder': "Comment"}]], - ['div', - ['input', {'type': 'submit', 'value': 'Add Comment'}]], - ])); - - $('input[type="submit"]', rv).on('click', function(event) { - func(rv, id); - event.stop(); - }); - return rv; -} - - -function extract(form, parent) { - return { - text: $('textarea[id="comment"]', form).val() || null, - author: $('input[id="author"]', form).val() || null, - email: $('input[id="email"]', form).val() || null, - website: $('input[id="website"]', form).val() || null, - parent: parent - }; -} - - -function edit() { - -} - - -function commit(form, parent) { - isso.create(extract(form, parent), function(status, rv) { - if (status == 201 || status == 202) { - insert(JSON.parse(rv)); - } - }); -} - - -var insert = function insert(post) { - /* - Insert a comment into #isso_thread. - - :param post: JSON from API call - */ - - var path = encodeURIComponent(window.location.pathname), - date = new Date(parseInt(post['created']) * 1000); - - // create
    for parent, if used - if (post['parent']) - $('#isso_' + post['parent']).append('
      '); - - $(post['parent'] ? '#isso_' + post['parent'] + ' > ul:last-child' : '#isso_thread > ul') - .append(brew([ - 'article', {'class': 'isso', 'id': 'isso_' + post['id']}, - ['header'], ['div'], ['footer'] - ])); - - var node = $('#isso_' + post['id']), - author = post['author'] || 'Anonymous'; - - if (post['website']) - author = brew(['a', {'href': post['website'], 'rel': 'nofollow'}]); - - // deleted - if (post['mode'] == 4) { - node.addClass('deleted'); - $('header', node).append('Kommentar entfernt') - $('div', node).append('

       

      ') - return; - } - - $('header', node).append('' + author + ''); - if (post['mode'] == 2 ) - $('header', node).append(brew(['span', {'class': 'note'}, 'Kommentar muss noch freigeschaltet werden'])); - - $('div', node).html(post['text']); - - $('footer', node).append(brew([ - 'a', {'href': '#'}, 'Antworten', - ])).append(brew([ - 'a', {'href': '#isso_' + post['id']}, '#' + post['id'], - ])).append(brew([ - 'time', {'datetime': date.getUTCFullYear() + '-' + date.getUTCMonth() + '-' + date.getUTCDate()}, format(date) - ])); - - if (read(path + '-' + post['id'])) { - $('#isso_' + post['id'] + '> footer > a:first-child') - .after(brew(['a', {'class': 'delete', 'href': '#'}, 'Löschen'])) - .after(brew(['a', {'class': 'edit', 'href': '#'}, 'Bearbeiten'])); - - // DELETE - $('#isso_' + post['id'] + ' > footer .delete').on('click', function(event) { - isso.remove(post['id'], function(status, rv) { - // XXX comment might not actually deleted - $('#isso_' + post['id']).remove(); - }); - event.stop(); - }); - - // EDIT - $('#isso_' + post['id'] + ' > footer .edit').on('click', function(event) { - - if ($('#issoform_' + post['id']).length == 0) { // HTML form not shown - isso.plain(post['id'], function(status, rv) { - if (status != 200) return alert('Mööp'); - var rv = form(post['id'], JSON.parse(rv), function(form, id) { - isso.modify(id, extract(form, post['parent']), function(status, rv) { - if (status != 200) return alert('Mööp'); - - $('#issoform_' + post['id']).remove(); - $('#isso_' + post['id']).remove(); - insert(JSON.parse(rv)); - }); - }); - - $('#isso_' + post['id']).after(rv); - $('input[type="submit"]', rv)[0].value = 'Bestätigen.'; - }); - } else { - $('#issoform_' + post['id']).remove(); - } - event.stop(); - }); - } - - // ability to answer directly to a comment - $('footer > a:first-child', '#isso_' + post['id']).on('click', function(event) { - - if ($('#issoform_' + post['id']).length == 0) { // HTML form not shown - $('#isso_' + post['id']).after(form(post['id'], {}, function(form, id) { - commit(form, id); - // XXX: animation (aka user feedback) - $('#issoform_' + post['id']).remove(); - })); - } else { - $('#issoform_' + post['id']).remove(); - } - event.stop(); - }); -} - - -/* - * initialize form and fetch recent comments - */ - -function initialize(thread) { - var html; - - thread.append('
        '); - $('head').append(''); - - html = form(null, {}, commit); - thread.append(html); -} - - -function fetch(thread) { - $.ajax('GET', isso.prefix + '/1.0/' + encodeURIComponent(window.location.pathname), - {}, {'Content-Type': 'application/json'}).then(function(status, rv) { - - if (status != 200) { - return - } - - rv = JSON.parse(rv); - for (var item in rv) { - insert(rv[item]); - } - }); -} - - -$.domReady(function() { - - // initialize comment form and css - initialize($('#isso_thread')); - - // fetch comments for path - fetch($('#isso_thread')); - - // REMOVE ME - $('input[id="author"]').val("Peter"); - $('textarea[id="comment"]').val("Lorem ipsum ..."); - -}); diff --git a/isso/client/isso.js b/isso/client/isso.js deleted file mode 100644 index 68d7812..0000000 --- a/isso/client/isso.js +++ /dev/null @@ -1,58 +0,0 @@ -/* Isso – Ich schrei sonst! - * - * Copyright 2013, Martin Zimmermann . All rights reserved. - * License: BSD Style, 2 clauses. See isso/__init__.py. - */ - -// Uhm. Namespaces are one honking great idea, aren't they? -var isso = {}; - - -var init = function() { - var isso = new Object(); - - // guess Isso API location - var js = document.getElementsByTagName("script"); - for (var i = 0; i < js.length; i++) { - if (js[i].src.match("/client/require\\.js$")) { - isso.location = js[i].src.substring(0, 18); - break; - } - } - - console.log(isso.location) -} - - -isso.create = function(data, func) { - - var request = new XMLHttpRequest(); - -// $.ajax('POST', prefix + '/1.0/' + isso.path + '/new', -// JSON.stringify(data), {'Content-Type': 'application/json'}).then(func); -}; - - -isso.modify = function(id, data, func) { - if (!verify(data)) { - return; - } - - $.ajax('PUT', prefix + '/1.0/' + isso.path + '/' + id, - JSON.stringify(data), {'Content-Type': 'application/json'}).then(func) -}; - - -isso.plain = function(id, func) { - $.ajax('GET', prefix + '/1.0/' + isso.path + '/' + id, {'plain': '1'}).then(func); -} - - -isso.remove = function(id, func) { - $.ajax('DELETE', prefix + '/1.0/' + isso.path + '/' + id).then(func); -} - - -isso.approve = function (id, func) { - $.ajax('PUT', '/1.0/' + isso.path + '/' + id + '/approve').then(func) -} diff --git a/isso/client/main.js b/isso/client/main.js deleted file mode 100644 index 1c247cf..0000000 --- a/isso/client/main.js +++ /dev/null @@ -1,6 +0,0 @@ -require(["minified"], function(minified) { - console.log(minified) - minified.$.ready(function() { - console.log(123); - }) -});