=s-1}if(s){r.e=true;r.k=r.f;q.shift().n(s)}else{if(p){q[0].k=r.f}r=q[0];r.g++;r.n(s);return r}};new g(l);m.each(["unwait","unrepeat"],function(p,o){m.fn[o]=function(){return this.trigger(o,arguments)}});m.each(["wait","repeat","join","then","unwait","unrepeat"],function(p,o){m[o]=function(){var q=typeof arguments[0]=="string"?Array.prototype.shift.apply(arguments):"";return m.fn[o].apply(d[q]=(d[q]||m("").text(q)),arguments)}});function b(r,u,q){if(typeof r=="string"){q=new Function("x","return ["+r+"\n,x]");r=function(w,v){v=q(w);p.x=v[1];return v[0]}}var o=typeof u=="function",t=typeof r=="function",p=function(v){if(arguments.length==1){p.x=v;if(o){u(v)}}else{return s()}};function s(v){v=o?u():p.x;return t?r(v):v}p.x=0;p._={toString:p.$=p.toString=s.toString=s};p.mod=function(v){return b(function(w){return w%v},p)};p.add=function(v){return b(function(w){return w+v},p)};p.neg=function(){return b("-x",p)};p.$$=p.X=function(v){return b(v,p)};m.each("abcdefghij",function(v,w){p[v]=p[w]=function(){p(arguments[v])}});return p}j.$$=m.$$=m.X=b;m.fn.$=function(){var o=m.apply(j,arguments);o.prevObject=this;return o}})(jQuery,window);
\ No newline at end of file
diff --git a/public_html/static/js/jsde.js b/public_html/static/js/jsde.js
index 59612f5..8146009 100755
--- a/public_html/static/js/jsde.js
+++ b/public_html/static/js/jsde.js
@@ -114,6 +114,11 @@ function JsdeWindow(options)
}
this.BringToForeground();
+
+ if(typeof jsde_creation_hook === "function")
+ {
+ jsde_creation_hook(this);
+ }
}
JsdeWindow.prototype.BringToForeground = function()
@@ -173,8 +178,14 @@ JsdeWindow.prototype.SetSize = function(width, height)
JsdeWindow.prototype.SetContents = function(html)
{
- console.log("set contents", html, this);
- return $(this._inner).html(html);
+ var returnval = $(this._inner).html(html);
+
+ if(typeof jsde_contents_hook === "function")
+ {
+ jsde_contents_hook(this);
+ }
+
+ return returnval;
}
JsdeWindow.prototype.SetTitle = function(html)
diff --git a/public_html/static/js/openng.js b/public_html/static/js/openng.js
index 9f3f56b..d6378a3 100644
--- a/public_html/static/js/openng.js
+++ b/public_html/static/js/openng.js
@@ -1,3 +1,20 @@
+var jsde_creation_hook = function(win)
+{
+ /* This function is a hook that is called after each creation of
+ * a JSDE window. */
+
+}
+
+var jsde_contents_hook = function(win)
+{
+ /* This function is a hook that is called after each time
+ * content is set in a JSDE window. */
+ placeHooksForWindow(win);
+}
+
+notification_popups = [];
+error_popups = [];
+
function hookSubmitEvent(form, callback, error)
{
/* Hooks a form to be submitted via AJAX, executing the given
@@ -11,18 +28,48 @@ function hookSubmitEvent(form, callback, error)
form.each(function(index){
var element = $(this);
- var method = element.attr("method").toUpperCase();
+ var method = element.attr("method");
var target = element.attr("action");
+ if(typeof method !== "undefined")
+ {
+ method = method.toUpperCase();
+ }
+ else
+ {
+ method = "GET";
+ }
+
element.submit(function(){
+ var submit_button = element.find("button[type=submit]");
+ var submit_icon = submit_button.data("submit-icon");
+
+ if(typeof submit_icon !== "undefined")
+ {
+ /* First we will try to replace an existing icon
+ * in the button. If there is no icon yet, the
+ * entire contents of the button will be replaced
+ * with the submission icon. */
+ var current_icon = submit_button.find("i");
+
+ if(current_icon.length == 0)
+ {
+ submit_button.html("");
+ current_icon = element.find("i");
+ }
+
+ current_icon.removeClass().addClass(submit_icon);
+ }
+
var formdata = element.serialize();
console.log(formdata);
$.ajax({
type: method,
url: target,
data: formdata,
- success: callback,
- error: error
+ dataType: "json",
+ success: function(data, xhr){ console.log(data); callback(element, data, xhr); },
+ error: function(data, xhr, err){ error(element, data, xhr, err); }
});
return false;
@@ -30,6 +77,69 @@ function hookSubmitEvent(form, callback, error)
});
}
+function placeHooksForWindow(win)
+{
+ console.log();
+ $(win._outer).find("form").each(function(){
+ var callback = $(this).data("hook-callback");
+
+ if(typeof callback !== "undefined")
+ {
+ console.log("Hooking", this, "using callback", callback);
+ hookSubmitEvent($(this), window[callback]);
+ }
+ });
+}
+
+function callbackNodeCreated(form, data)
+{
+ if(data.result == "success")
+ {
+ spawnNotification(data.message);
+ var node_id = data.node_id;
+
+ form.getWindow().Close();
+
+ new JsdeWindow({
+ width: 480,
+ height: 300,
+ x: 100,
+ y: 100,
+ title: "Node lookup",
+ contents: "Loading...",
+ source_url: "/nodes/" + node_id
+ });
+ }
+ else if(data.result == "error")
+ {
+ spawnError(data.message);
+ }
+}
+
+function spawnNotification(message)
+{
+ var popup = spawnPopup(message, "notification");
+ notification_popups.push(popup);
+}
+
+function spawnError(message)
+{
+ var popup = spawnPopup(message, "error");
+ error_popups.push(popup);
+}
+
+function spawnPopup(message, template)
+{
+ var popup = $("#jsde_templates").find(".template_" + template).clone().removeClass("template_notification template_error");
+ popup.find(".message").html(message.replace("\n", "
"));
+ popup.hide();
+ popup.prependTo("#notification_area");
+
+ popup.fadeIn(300).wait(5000).fadeOut(400, $).remove();
+
+ return popup
+}
+
$(function(){
hookSubmitEvent($("#form_search"));
@@ -56,4 +166,7 @@ $(function(){
contents: "Loading...",
source_url: "/intro"
});
+
+ spawnNotification("Test notification");
+ spawnError("Test error");
});
diff --git a/public_html/templates/index.tpl b/public_html/templates/index.tpl
index 208a366..2bc0c4a 100644
--- a/public_html/templates/index.tpl
+++ b/public_html/templates/index.tpl
@@ -5,6 +5,7 @@
+