From 26c74cb5213ea18fca728d250acde184def059c0 Mon Sep 17 00:00:00 2001 From: posativ Date: Mon, 17 Dec 2012 00:00:49 +0100 Subject: [PATCH] admin.js now used isso.js as API JS is a horrible language. The more you try to modularize and DRY it, the greater the LoC grows... --- Makefile | 11 +++++++++-- isso/{templates => js}/admin.js | 23 ++++++++++++++--------- isso/js/isso.js | 13 +++++++++---- isso/templates/admin.mako | 4 ---- isso/templates/base.mako | 13 ++++--------- isso/templates/login.mako | 3 +-- 6 files changed, 37 insertions(+), 30 deletions(-) rename isso/{templates => js}/admin.js (61%) diff --git a/Makefile b/Makefile index 4372158..b7078ec 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ISSO = "isso/js" -all: js +all: admin client init: git clone https://github.com/posativ/promisejs.git $(ISSO)/promise.js @@ -8,7 +8,14 @@ init: (cd $(ISSO) && ender add promise.js) rm -rf $(ISSO)/promise.js -js: +admin: + cat $(ISSO)/ender.js $(ISSO)/isso.js $(ISSO)/utils.js $(ISSO)/admin.js > $(ISSO)/_.js + yuicompressor --type js --charset utf-8 $(ISSO)/_.js -o $(ISSO)/interface.js + + rm $(ISSO)/_.js + +client: cat $(ISSO)/ender.js $(ISSO)/isso.js $(ISSO)/utils.js $(ISSO)/client.js > $(ISSO)/_.js yuicompressor --type js --charset utf-8 $(ISSO)/_.js -o $(ISSO)/embed.js + rm $(ISSO)/_.js diff --git a/isso/templates/admin.js b/isso/js/admin.js similarity index 61% rename from isso/templates/admin.js rename to isso/js/admin.js index 05d1043..a762267 100644 --- a/isso/templates/admin.js +++ b/isso/js/admin.js @@ -1,29 +1,34 @@ +/* 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] - var path = node.getAttribute("data-path"); - var id = node.getAttribute("data-id"); + 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) { - $.ajax('PUT', '/1.0/' + encodeURIComponent(path) + '/' + id + '/approve') - .then(function(status, rv) { + isso.approve(id, function(status, rv) { $(node).prependTo($('#approved')); $('.approve', node).remove(); - }); + }); event.stop(); }); } else { $(item).on('click', function(event) { if (confirm("RLY?") == true) { - $.ajax('DELETE', '/1.0/' + encodeURIComponent(path) + '/' + id) - .then(function() { + isso.remove(id, function(status, rv) { $(node).remove() }); - }; + }; event.stop(); }); }; diff --git a/isso/js/isso.js b/isso/js/isso.js index 5499278..b49ccc5 100644 --- a/isso/js/isso.js +++ b/isso/js/isso.js @@ -34,7 +34,7 @@ isso.create = function(data, func) { return; } - $.ajax('POST', prefix + '/1.0/' + path + '/new', + $.ajax('POST', prefix + '/1.0/' + isso.path + '/new', JSON.stringify(data), {'Content-Type': 'application/json'}).then(func); }; @@ -44,16 +44,21 @@ isso.modify = function(id, data, func) { return; } - $.ajax('PUT', prefix + '/1.0/' + path + '/' + id, + $.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/' + path + '/' + id, {'plain': '1'}).then(func); + $.ajax('GET', prefix + '/1.0/' + isso.path + '/' + id, {'plain': '1'}).then(func); } isso.remove = function(id, func) { - $.ajax('DELETE', prefix + '/1.0/' + path + '/' + id).then(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/templates/admin.mako b/isso/templates/admin.mako index f2564b1..4ce48d3 100644 --- a/isso/templates/admin.mako +++ b/isso/templates/admin.mako @@ -1,9 +1,5 @@ <%inherit file="base.mako"/> -<%block name="js"> - <%include file="admin.js"/> - - <% from time import strftime, gmtime diff --git a/isso/templates/base.mako b/isso/templates/base.mako index a682b0b..1aff922 100644 --- a/isso/templates/base.mako +++ b/isso/templates/base.mako @@ -2,11 +2,8 @@ <%block name="title" /> - - +