Auto-create new property fields when existing fields are filled in

feature/core
Sven Slootweg 11 years ago
parent 59761e6412
commit 6a03a11c1e

@ -42,3 +42,7 @@ if(!empty($router->uVariables['json']))
{
echo(json_encode($sData));
}
$sNode = new Node(1);
$sNode->uName = random_string(15);
$sNode->InsertIntoDatabase();

@ -1,3 +1,9 @@
(function($){
$.fn.restoreIcon = function() {
return this.removeClass().addClass(this.data("old-class"));
};
})(jQuery);
var jsde_creation_hook = function(win)
{
/* This function is a hook that is called after each creation of
@ -14,6 +20,7 @@ var jsde_contents_hook = function(win)
notification_popups = [];
error_popups = [];
template_cache = {};
function hookSubmitEvent(form, callback, error)
{
@ -58,7 +65,7 @@ function hookSubmitEvent(form, callback, error)
current_icon = element.find("i");
}
current_icon.removeClass().addClass(submit_icon);
current_icon.data("old-class", current_icon.attr("class")).removeClass().addClass(submit_icon);
}
var formdata = element.serialize();
@ -82,11 +89,12 @@ function placeHooksForWindow(win)
console.log();
$(win._outer).find("form").each(function(){
var callback = $(this).data("hook-callback");
var error_callback = $(this).data("hook-error-callback");
if(typeof callback !== "undefined")
{
console.log("Hooking", this, "using callback", callback);
hookSubmitEvent($(this), window[callback]);
hookSubmitEvent($(this), window[callback], window[error_callback]);
}
});
}
@ -112,10 +120,16 @@ function callbackNodeCreated(form, data)
}
else if(data.result == "error")
{
form.find("button[type=submit] i").restoreIcon();
spawnError(data.message);
}
}
/*function callbackNodeCreationFailed(form, data)
{
form.find("button[type=submit]").restoreIcon();
}*/
function spawnNotification(message)
{
var popup = spawnPopup(message, "notification");
@ -140,6 +154,16 @@ function spawnPopup(message, template)
return popup
}
function spawnTemplate(name)
{
if(!template_cache[name])
{
template_cache[name] = $("*[data-template-name=" + name + "]").first();
}
return template_cache[name].clone();
}
$(function(){
hookSubmitEvent($("#form_search"));
@ -169,4 +193,14 @@ $(function(){
spawnNotification("Test notification");
spawnError("Test error");
$("body").on("input", ".auto-duplicate input", function(){
var parent = $(this).closest(".auto-duplicate");
if(!parent.data("duplicated"))
{
spawnTemplate(parent.data("template-name")).insertAfter(parent).find("input").val("");
parent.data("duplicated", true);
}
})
});

@ -30,12 +30,7 @@
<h1 class="form">Properties</h1>
</div>
<div class="property">
<input type="text" class="pure-input-1-2 group-first" name="property_name[]" placeholder="Name">
<input type="text" class="pure-input-1-2 group-last" name="property_value[]" placeholder="Value">
</div>
<div class="property">
<div class="property auto-duplicate" data-template-name="createnode_property">
<input type="text" class="pure-input-1-2 group-first" name="property_name[]" placeholder="Name">
<input type="text" class="pure-input-1-2 group-last" name="property_value[]" placeholder="Value">
</div>

Loading…
Cancel
Save