Skip to content

Commit

Permalink
Merge branch 'feature/multiposting_with_select2' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
TiSiE committed May 27, 2015
2 parents 7601f11 + 60714bb commit eb61733
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 205 deletions.
84 changes: 41 additions & 43 deletions module/Core/public/js/jquery.summary-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ holdupRefUntiliFramesAreSaved = function (targetRef, triggerRef) {
this.$summaryContainer.hide().css('opacity', 0);
}

this.$formContainer.find('form').on('yk.forms.done', $.proxy(this.submit, this));
this.$formContainer.find('form').on('yk.forms.done', $.proxy(this.submit, this))
.find(':input')
.change(function(e) {
$(e.target).parents('.sf-container').addClass("yk-changed");
});
this.$formContainer.find('.sf-cancel').click($.proxy(this.cancel, this));

}
Expand All @@ -137,61 +141,55 @@ holdupRefUntiliFramesAreSaved = function (targetRef, triggerRef) {
/**
* ensures that all forms in the summary-form are saved before executing a link
*/
$.fn.summaryformEnsureSave = function ()
$.fn.summaryform.ensureSave = function (event)
{
//console.log("a onClick", this);
$(this).click(function(event) {
var returnValue = true;
var eventTarget = event.target;
$(".sf-container").each(function() {
var containers = $(this);
if (containers.hasClass("yk-changed")) {
//console.log("test-container", containers, containers.hasClass("yk-changed"));
var sfForm = $(this).find(".sf-form");
var sfSummary = $(this).find(".sf-summary");
var title = $(this).find(".sf-headline").text();
if (sfForm.length == 1 && sfSummary.length == 1) {
//console.log(title, sfForm.css("display"), sfSummary.css("display"));
if (sfForm.css("display") == "block" && sfSummary.css("display") == "none") {
var res = confirm("Form '" + title + "' has not been saved\ncontinue ?");
if (!res) {
// set the return-value and end the loop, so that you don't have to go through all other open forms
returnValue = false;
// this return is intentional, it ends the each loop primarily - like a break statement would end a normal for-loop
return false;
}
else {
containers.removeClass('yk-changed');
}
var returnValue = true;
var eventTarget = event.target;

if (eventTarget.href.match(/#/)) {
return true;
}

$(".sf-container").each(function() {
var containers = $(this);
if (containers.hasClass("yk-changed")) {
//console.log("test-container", containers, containers.hasClass("yk-changed"));
var sfForm = $(this).find(".sf-form");
var sfSummary = $(this).find(".sf-summary");
var title = $(this).find(".sf-headline").text();
if (sfForm.length == 1 && sfSummary.length == 1) {
//console.log(title, sfForm.css("display"), sfSummary.css("display"));
if (sfForm.css("display") == "block" && sfSummary.css("display") == "none") {
var res = confirm("Form '" + title + "' has not been saved\ncontinue ?");
if (!res) {
// set the return-value and end the loop, so that you don't have to go through all other open forms
returnValue = false;
// this return is intentional, it ends the each loop primarily - like a break statement would end a normal for-loop
return false;
}
else {
containers.removeClass('yk-changed');
}
}
}
});
//console.log("returnValue", returnValue);
}
});
//console.log("returnValue", returnValue);

// test for not saved tinyMC-Editoren in the iFrame
returnValue = returnValue && holdupRefUntiliFramesAreSaved(eventTarget, false);
// test for not saved tinyMC-Editoren in the iFrame
returnValue = returnValue && holdupRefUntiliFramesAreSaved(eventTarget, false);

return returnValue;
});
}
return returnValue;

$.fn.markChangeTrigger = function ()
{
$(this).find(":input").change(function(event) {
var target = event.target;
console.log('changed', target);
$(target).parents(".sf-container").addClass("yk-changed");
});
}
};

/**
* initialize on DocumentReady here
*/
$(function() {
$(".sf-container").summaryform();
$("a").summaryformEnsureSave();
$(".sf-container").markChangeTrigger();
$("a").click($.fn.summaryform.ensureSave);
//$(".sf-container").markChangeTrigger();
});

})(jQuery);
101 changes: 81 additions & 20 deletions module/Jobs/public/js/form.multiposting-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,118 @@
;
(function ($) {

var resultTmpl = null;
var selectTmpl = null;
var numberFormat = {
'delimiter': ',',
'decimal': '.'
};


function displayResult(item)
{
if (item.children) {
return item.text;
}

console.debug(item);
var data = parseTextToJson(item.text);
console.debug(data);
var data = $.fn.multipostingSelect.getOptionData(item.text);

var link = '<a href="' + data.link + '">' + data.linkText + '</a>';
var desc = data.desc.replace(/%s/, link);
data.desc = data.desc.replace(/%s/, link);

return $('<strong>' + data.name + ' - ' + data.headline + '</strong><br><small>' + desc + '</small>');
return tmpl(resultTmpl, data);
}

function displaySelection(item)
{
var data = parseTextToJson(item.text);
var data = $.fn.multipostingSelect.getOptionData(item.text);

return data.name + ' ( ' + data.duration + ' )';
return tmpl(selectTmpl, data);
}

function parseTextToJson(text)
function updatePrice(e)
{
var textArr = text.split('|');
var $select = $(e.target);
var selected = $select.find('option:selected');
var sum = $.fn.multipostingSelect.calculatePrice(selected);
var price = $.fn.multipostingSelect.formatPrice(sum, numberFormat);

$('#' + $select.attr('id') + '-total span').text(price);

return {
name: textArr[0],
headline: textArr[1],
desc: textArr[2],
linkText: textArr[3],
link: textArr[4],
duration: textArr[5]
};
}

function tmpl(template, vars)
{
for (var key in vars) {
var search = new RegExp('%' + key, 'gi');
template = template.replace(search, vars[key]);
}

return template;
}

$(function() {
var $select = $('#jobPortals-channel');
var $select = $('#jobPortals-portals');
var data = $select.data();
//var $eventSelect = $(".js-example-events");

// get templates
var id = $select.attr('id');
resultTmpl = $('span#' + id + '-result-tmpl').data('template');
selectTmpl = $('span#' + id + '-select-tmpl').data('template');
numberTmpl = $('span#' + id + '-currency-tmpl').data('template');
numberFormat.delimiter = numberTmpl.substr(1,1);
numberFormat.decimal = numberTmpl.substr(5,1);

$select.select2({
//allowClear: true,
placeholder: data.placeholder,
formatResult: displayResult,
formatSelection: displaySelection
});
console.debug($select);

$select.on("change", updatePrice);
$select.trigger('change');
});

$.fn.multipostingSelect = {};
$.fn.multipostingSelect.formatPrice = function(price, numberFormat)
{
price = price.toFixed(2)
.replace(".", numberFormat.decimal)
.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1" + numberFormat.delimiter);

return price;

};

$.fn.multipostingSelect.calculatePrice = function(selectedOptions)
{
var sum = 0;

for (var i= 0, c=selectedOptions.length; i<c; i+=1) {
var data = $.fn.multipostingSelect.getOptionData($(selectedOptions[i]).text());
sum += data.price;
}

return sum;
};

$.fn.multipostingSelect.getOptionData = function(text)
{
var textArr = text.split('|');

return {
name: textArr[0],
headline: textArr[1],
desc: textArr[2],
linkText: textArr[3],
link: textArr[4],
duration: textArr[5],
nicePrice: textArr[6],
price: parseFloat(textArr[7])

};
};

})(jQuery);

2 changes: 1 addition & 1 deletion module/Jobs/src/Jobs/Entity/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class Job extends BaseEntity implements JobInterface, DraftableEntityInterface {
* Can contain various Portals
*
* @var array
* @ODM\Hash*/
* @ODM\Collection*/
protected $portals = array();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public function createService(ServiceLocatorInterface $serviceLocator)
. $channel->getHeadLine() . '|'
. $channel->getDescription() . '|'
. $channel->getLinkText() . '|'
. $link . '|' . $channel->getPublishDuration();
. $link . '|' . $channel->getPublishDuration() . '|'
. $channel->getFormattedPrice() . '|'
. $channel->getPrice();
}


Expand Down
Loading

0 comments on commit eb61733

Please sign in to comment.