Commit 8c6ae374 authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

Retain placeholders when expanding template. This allows for re-expand.

parent 2fbe6110
......@@ -25,14 +25,15 @@ var QfqNS = QfqNS || {};
return;
}
var expandedTemplate = n.replacePlaceholder($template.text(), lines);
var deserializedTemplate = n.deserializeTemplateAndRetainPlaceholders($template.text());
n.expandRetainedPlaceholders(deserializedTemplate, lines);
$target.append(expandedTemplate);
$target.append(deserializedTemplate);
};
n.initializeFields = function (element, templateSelectorData) {
var $element = $(element);
var templateSelector, escapedTemplateSelector, $template, $deserializedTemplate, expandedTemplate;
var templateSelector, escapedTemplateSelector, $template, deserializedTemplate;
if ($element.children().length > 0) {
// already initialized
......@@ -44,18 +45,52 @@ var QfqNS = QfqNS || {};
$template = $(escapedTemplateSelector);
expandedTemplate = n.replacePlaceholder($template.text(), 0);
deserializedTemplate = n.deserializeTemplateAndRetainPlaceholders($template.text());
n.expandRetainedPlaceholders(deserializedTemplate, 0);
$deserializedTemplate = $(expandedTemplate);
$deserializedTemplate.find('.qfq-delete-button').remove();
$element.append($deserializedTemplate);
deserializedTemplate.find('.qfq-delete-button').remove();
$element.append(deserializedTemplate);
};
n.removeFields = function (target) {
$(target).closest('.qfq-line').remove();
};
/**
* @private
* @param template
*/
n.deserializeTemplateAndRetainPlaceholders = function (template) {
var $deserializedTemplate = $(template);
$deserializedTemplate.find("*").each(function () {
var $element = $(this);
$.each(this.attributes, function () {
if (this.value.indexOf('%d') !== -1) {
$element.data(this.name, this.value);
}
});
});
return $deserializedTemplate;
};
/**
* @private
* @param
*/
n.expandRetainedPlaceholders = function ($elements, value) {
$elements.find('*').each(function () {
var $element = $(this);
$.each(this.attributes, function () {
var retainedPlaceholder = $element.data(this.name);
if (retainedPlaceholder) {
this.value = n.replacePlaceholder(retainedPlaceholder, value);
}
});
});
};
/**
* @private
* @param targetSelector
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment