update Piwik to version 2.16 (fixes #91)

This commit is contained in:
oliver 2016-04-10 18:55:57 +02:00
commit d885a4baa9
5833 changed files with 418860 additions and 226988 deletions

View file

@ -1,5 +1,5 @@
/*!
* Piwik - Web Analytics
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
@ -7,6 +7,12 @@
Segmentation = (function($) {
function preselectFirstMetricMatch(rowNode)
{
var matchValue = $(rowNode).find('.metricMatchBlock option:first').attr('value');
$(rowNode).find('.metricMatchBlock select').val(matchValue);
}
var segmentation = function segmentation(config) {
if (!config.target) {
throw new Error("target property must be set in config to segment editor control element");
@ -26,6 +32,8 @@ Segmentation = (function($) {
self.timer = ""; // variable for further use in timing events
self.searchAllowed = true;
self.filterTimer = "";
self.filterAllowed = true;
self.availableMatches = [];
self.availableMatches["metric"] = [];
@ -35,12 +43,14 @@ Segmentation = (function($) {
self.availableMatches["metric"][">="] = self.translations['General_OperationAtLeast'];
self.availableMatches["metric"]["<"] = self.translations['General_OperationLessThan'];
self.availableMatches["metric"][">"] = self.translations['General_OperationGreaterThan'];
self.availableMatches["dimension"] = [];
self.availableMatches["dimension"]["=="] = self.translations['General_OperationIs'];
self.availableMatches["dimension"]["!="] = self.translations['General_OperationIsNot'];
self.availableMatches["dimension"]["=@"] = self.translations['General_OperationContains'];
self.availableMatches["dimension"]["!@"] = self.translations['General_OperationDoesNotContain'];
self.availableMatches["dimension"]["=^"] = self.translations['General_OperationStartsWith'];
self.availableMatches["dimension"]["=$"] = self.translations['General_OperationEndsWith'];
segmentation.prototype.setAvailableSegments = function (segments) {
this.availableSegments = segments;
@ -61,44 +71,23 @@ Segmentation = (function($) {
this.currentSegmentStr = segmentStr;
};
segmentation.prototype.shortenSegmentName = function(name, length){
if(typeof length === "undefined") length = 16;
if(typeof name === "undefined") name = "";
var i;
if(name.length > length)
{
for(i = length; i > 0; i--){
if(name[i] === " "){
break;
}
}
if(i == 0){
i = length-3;
}
return name.slice(0,i)+"...";
}
return name;
};
segmentation.prototype.markCurrentSegment = function(){
var current = this.getSegment();
var segmentationTitle = $(this.content).find(".segmentationTitle");
if( current != "")
{
var selector = 'div.segmentList ul li[data-definition="'+current+'"]';
var currentDecoded = piwikHelper.htmlDecode(current);
var selector = 'div.segmentList ul li[data-definition="'+currentDecoded+'"]';
var foundItems = $(selector, this.target);
var title = $('<strong></strong>');
if( foundItems.length > 0) {
var name = $(foundItems).first().find("span.segname").text();
title.text(name);
var idSegment = $(foundItems).first().attr('data-idsegment');
var title = getSegmentName( getSegmentFromId(idSegment));
} else {
title.text("Custom Segment");
title = _pk_translate('SegmentEditor_CustomSegment');
}
segmentationTitle.html(title);
segmentationTitle.addClass('segment-clicked').html( title );
}
else {
$(this.content).find(".segmentationTitle").text(this.translations['SegmentEditor_DefaultAllVisits']);
@ -120,26 +109,25 @@ Segmentation = (function($) {
};
var getMockedInputSet = function(){
if(typeof mockedInputSet === "undefined"){
var mockedInputSet = self.editorTemplate.find("div.segment-row-inputs").clone();
}
return mockedInputSet.clone();
var mockedInputSet = self.editorTemplate.find("div.segment-row-inputs").clone();
var clonedInput = mockedInputSet.clone();
preselectFirstMetricMatch(clonedInput);
return clonedInput;
};
var getMockedInputRowHtml = function(){
if(typeof mockedInputRow === "undefined"){
var mockedInputRow = '<div class="segment-row"><a class="segment-close" href="#"></a><div class="segment-row-inputs">'+getMockedInputSet().html()+'</div></div>';
}
var mockedInputRow = '<div class="segment-row"><a class="segment-close" href="#"></a><div class="segment-row-inputs">'+getMockedInputSet().html()+'</div></div>';
return mockedInputRow;
};
var getMockedFormRow = function(){
if(typeof mockedFormRow === "undefined")
{
var mockedFormRow = self.editorTemplate.find("div.segment-rows").clone();
$(mockedFormRow).find(".segment-row").append(getMockedInputSet()).after(getAddOrBlockButtonHtml).after(getOrDiv());
}
return mockedFormRow.clone();
var mockedFormRow = self.editorTemplate.find("div.segment-rows").clone();
$(mockedFormRow).find(".segment-row").append(getMockedInputSet()).after(getAddOrBlockButtonHtml).after(getOrDiv());
var clonedRow = mockedFormRow.clone();
preselectFirstMetricMatch(clonedRow);
return clonedRow;
};
var getInitialStateRowsHtml = function(){
@ -156,11 +144,13 @@ Segmentation = (function($) {
};
var appendSpecifiedRowHtml= function(metric) {
$(self.form).find(".segment-content > h3").after(getMockedFormRow());
var mockedRow = getMockedFormRow();
$(self.form).find(".segment-content > h3").after(mockedRow);
$(self.form).find(".segment-content").append(getAndDiv());
$(self.form).find(".segment-content").append(getAddNewBlockButtonHtml());
doDragDropBindings();
$(self.form).find(".metricList").val(metric).trigger("change");
preselectFirstMetricMatch(mockedRow);
};
var appendComplexRowHtml = function(block){
@ -208,28 +198,68 @@ Segmentation = (function($) {
var getListHtml = function() {
var html = self.editorTemplate.find("> .listHtml").clone();
var segment, injClass;
var listHtml = '<li data-idsegment="" ' +
(self.currentSegmentStr == "" ? " class='segmentSelected' " : "")
+ ' data-definition=""><span class="segname">' + self.translations['SegmentEditor_DefaultAllVisits']
+ ' ' + self.translations['General_DefaultAppended']
+ '</span></li> ';
(self.currentSegmentStr == "" ? " class='segmentSelected' " : "")
+ ' data-definition=""><span class="segname">' + self.translations['SegmentEditor_DefaultAllVisits']
+ ' ' + self.translations['General_DefaultAppended']
+ '</span></li> ';
var isVisibleToSuperUserNoticeAlreadyDisplayedOnce = false;
var isVisibleToSuperUserNoticeShouldBeClosed = false;
var isSharedWithMeBySuperUserNoticeAlreadyDisplayedOnce = false;
var isSharedWithMeBySuperUserNoticeShouldBeClosed = false;
if(self.availableSegments.length > 0) {
for(var i = 0; i < self.availableSegments.length; i++)
{
segment = self.availableSegments[i];
if(isSegmentSharedWithMeBySuperUser(segment) && !isSharedWithMeBySuperUserNoticeAlreadyDisplayedOnce) {
isSharedWithMeBySuperUserNoticeAlreadyDisplayedOnce = true;
isSharedWithMeBySuperUserNoticeShouldBeClosed = true;
listHtml += '<span class="segmentsSharedWithMeBySuperUser"><hr> ' + _pk_translate('SegmentEditor_SharedWithYou') + ':<br/><br/>';
}
if(isSegmentVisibleToSuperUserOnly(segment) && !isVisibleToSuperUserNoticeAlreadyDisplayedOnce) {
// close <span class="segmentsSharedWithMeBySuperUser">
if(isSharedWithMeBySuperUserNoticeShouldBeClosed) {
isSharedWithMeBySuperUserNoticeShouldBeClosed = false;
listHtml += '</span>';
}
isVisibleToSuperUserNoticeAlreadyDisplayedOnce = true;
isVisibleToSuperUserNoticeShouldBeClosed = true;
listHtml += '<span class="segmentsVisibleToSuperUser"><hr> ' + _pk_translate('SegmentEditor_VisibleToSuperUser') + ':<br/><br/>';
}
injClass = "";
if( segment.definition == self.currentSegmentStr){
var checkSelected = segment.definition;
if(!$.browser.mozilla) {
checkSelected = encodeURIComponent(checkSelected);
}
if( checkSelected == self.currentSegmentStr){
injClass = 'class="segmentSelected"';
}
listHtml += '<li data-idsegment="'+segment.idsegment+'" data-definition="'+ (segment.definition).replace(/"/g, '&quot;') +'" '
+ injClass +' title="'+segment.name+'"><span class="segname">'
+ self.shortenSegmentName(segment.name)+'</span>';
+injClass+' title="'+ getSegmentTooltipEnrichedWithUsername(segment) +'"><span class="segname">'+getSegmentName(segment)+'</span>';
if(self.segmentAccess == "write") {
listHtml += '<span class="editSegment">['+ self.translations['General_Edit'].toLocaleLowerCase() +']</span>';
listHtml += '<span class="editSegment" title="'+ self.translations['General_Edit'].toLocaleLowerCase() +'"></span>';
}
listHtml += '</li>';
}
if(isVisibleToSuperUserNoticeShouldBeClosed) {
listHtml += '</span>';
}
if(isSharedWithMeBySuperUserNoticeShouldBeClosed) {
listHtml += '</span>';
}
$(html).find(".segmentList > ul").append(listHtml);
if(self.segmentAccess === "write"){
$(html).find(".add_new_segment").html(self.translations['SegmentEditor_AddNewSegment']);
@ -245,20 +275,58 @@ Segmentation = (function($) {
return html;
};
var isSegmentVisibleToSuperUserOnly = function(segment) {
return hasSuperUserAccessAndSegmentCreatedByAnotherUser(segment)
&& segment.enable_all_users == 0;
};
var isSegmentSharedWithMeBySuperUser = function(segment) {
return segment.login != piwik.userLogin
&& segment.enable_all_users == 1;
};
var hasSuperUserAccessAndSegmentCreatedByAnotherUser = function(segment) {
return piwik.hasSuperUserAccess && segment.login != piwik.userLogin;
};
var getSegmentTooltipEnrichedWithUsername = function(segment) {
var segmentName = segment.name;
if(hasSuperUserAccessAndSegmentCreatedByAnotherUser(segment)) {
segmentName += ' (';
segmentName += _pk_translate('General_CreatedByUser', [segment.login]);
if(segment.enable_all_users == 0) {
segmentName += ', ' + _pk_translate('SegmentEditor_VisibleToSuperUser');
}
segmentName += ')';
}
return sanitiseSegmentName(segmentName);
};
var getSegmentName = function(segment) {
return sanitiseSegmentName(segment.name);
};
var sanitiseSegmentName = function(segment) {
segment = piwikHelper.escape(segment);
return segment;
}
var getFormHtml = function() {
var html = self.editorTemplate.find("> .segment-element").clone();
// set left margin to center form
var segmentsDropdown = $(html).find(".available_segments_select");
var segment, newOption;
newOption = '<option data-idsegment="" data-definition="" title="'
+ self.translations['SegmentEditor_AddNewSegment']
+ '">' + self.translations['SegmentEditor_AddNewSegment']
+ '</option>';
+ self.translations['SegmentEditor_AddNewSegment']
+ '">' + self.translations['SegmentEditor_AddNewSegment']
+ '</option>';
segmentsDropdown.append(newOption);
for(var i = 0; i < self.availableSegments.length; i++)
{
segment = self.availableSegments[i];
newOption = '<option data-idsegment="'+segment.idsegment+'" data-definition="'+(segment.definition).replace(/"/g, '&quot;')+'" title="'+segment.name+'">'+self.shortenSegmentName(segment.name)+'</option>';
newOption = '<option data-idsegment="'+segment.idsegment+'" data-definition="'+(segment.definition).replace(/"/g, '&quot;')+'" title="'+getSegmentTooltipEnrichedWithUsername(segment)+'">'+getSegmentName(segment)+'</option>';
segmentsDropdown.append(newOption);
}
$(html).find(".segment-content > h3").after(getInitialStateRowsHtml()).show();
@ -267,14 +335,13 @@ Segmentation = (function($) {
var closeAllOpenLists = function() {
$(".segmentationContainer", self.target).each(function() {
if($(this).closest('.segmentEditorPanel').hasClass("visible"))
if($(this).closest('.segmentEditorPanel').hasClass("expanded"))
$(this).trigger("click");
});
};
var findAndExplodeByMatch = function(metric){
var matches = ["==" , "!=" , "<=", ">=", "=@" , "!@","<",">"];
var matches = ["==" , "!=" , "<=", ">=", "=@" , "!@","<",">", "=^", "=$"];
var newMetric = {};
var minPos = metric.length;
var match, index;
@ -332,10 +399,15 @@ Segmentation = (function($) {
var openEditForm = function(segment){
addForm("edit", segment);
$(self.form).find(".segment-content > h3 > span").text(segment.name);
$(self.form).find(".segment-content > h3 > span")
.html( getSegmentName(segment) )
.prop('title', getSegmentTooltipEnrichedWithUsername(segment));
$(self.form).find('.available_segments_select > option[data-idsegment="'+segment.idsegment+'"]').prop("selected",true);
$(self.form).find('.available_segments a.dropList').text(self.shortenSegmentName(segment.name, 16));
$(self.form).find('.available_segments a.dropList')
.html( getSegmentName(segment) )
.prop( 'title', getSegmentTooltipEnrichedWithUsername(segment));
if(segment.definition != ""){
revokeInitialStateRows();
@ -351,21 +423,67 @@ Segmentation = (function($) {
doDragDropBindings();
};
var bindEvents = function() {
var displayFormAddNewSegment = function (e) {
closeAllOpenLists();
addForm("new");
doDragDropBindings();
};
var filterSegmentList = function (keyword) {
var curTitle;
clearFilterSegmentList();
$(self.target).find(" .filterNoResults").remove();
$(self.target).find(".segmentList li").each(function () {
curTitle = $(this).prop('title');
$(this).hide();
if (curTitle.toLowerCase().indexOf(keyword.toLowerCase()) !== -1) {
$(this).show();
}
});
if ($(self.target).find(".segmentList li:visible").length == 0) {
$(self.target).find(".segmentList li:first")
.before("<li class=\"filterNoResults grayed\">" + self.translations['General_SearchNoResults'] + "</li>");
}
if ($(self.target).find(".segmentList .segmentsVisibleToSuperUser li:visible").length == 0) {
$(self.target).find(".segmentList .segmentsVisibleToSuperUser").hide();
}
if ($(self.target).find(".segmentList .segmentsSharedWithMeBySuperUser li:visible").length == 0) {
$(self.target).find(".segmentList .segmentsSharedWithMeBySuperUser").hide();
}
}
var clearFilterSegmentList = function () {
$(self.target).find(" .filterNoResults").remove();
$(self.target).find(".segmentList li").each(function () {
$(this).show();
});
$(self.target).find(".segmentList .segmentsVisibleToSuperUser").show();
$(self.target).find(".segmentList .segmentsSharedWithMeBySuperUser").show();
}
var bindEvents = function () {
self.target.on('click', '.segmentationContainer', function (e) {
// hide all other modals connected with this widget
if (self.content.closest('.segmentEditorPanel').hasClass("visible")) {
if ($(e.target).hasClass("jspDrag") === true) {
if (self.content.closest('.segmentEditorPanel').hasClass("expanded")) {
if ($(e.target).hasClass("jspDrag") === true
|| $(e.target).hasClass("segmentFilterContainer") === true
|| $(e.target).parents().hasClass("segmentFilterContainer") === true
|| $(e.target).hasClass("filterNoResults")) {
e.stopPropagation();
} else {
self.jscroll.destroy();
self.target.closest('.segmentEditorPanel').removeClass('visible');
if (self.jscroll) {
self.jscroll.destroy();
}
self.target.closest('.segmentEditorPanel').removeClass('expanded');
}
} else {
// for each visible segmentationContainer -> trigger click event to close and kill scrollpane - very important !
closeAllOpenLists();
self.target.closest('.segmentEditorPanel').addClass('visible');
self.target.closest('.segmentEditorPanel').addClass('expanded');
self.target.find('.segmentFilter').val(self.translations['General_Search']).trigger('keyup');
self.jscroll = self.target.find(".segmentList").jScrollPane({
autoReinitialise: true,
showArrows:true
@ -384,36 +502,68 @@ Segmentation = (function($) {
self.target.on("click", ".segmentList li", function (e) {
if ($(e.currentTarget).hasClass("grayed") !== true) {
var segment = {};
segment.idsegment = $(this).attr("data-idsegment");
segment.definition = $(this).data("definition");
segment.name = $(this).attr("title");
var idsegment = $(this).attr("data-idsegment");
segmentDefinition = $(this).data("definition");
self.setSegment(segment.definition);
self.setSegment(segmentDefinition);
self.markCurrentSegment();
self.segmentSelectMethod( segment.definition );
toggleLoadingMessage(segment.definition.length);
self.segmentSelectMethod( segmentDefinition );
toggleLoadingMessage(segmentDefinition.length);
}
});
self.target.on('click', '.add_new_segment', function (e) {
e.stopPropagation();
closeAllOpenLists();
addForm("new");
doDragDropBindings();
displayFormAddNewSegment(e);
});
self.target.on('change', "select.metricList", function (e, persist) {
if (typeof persist === "undefined") {
persist = false;
}
alterMatchesList(this, persist);
alterMatchesList(this, true);
doDragDropBindings();
autoSuggestValues(this, persist);
});
// attach event that will clear segment list filtering input after clicking x
self.target.on('click', ".segmentFilterContainer span", function (e) {
$(e.target).parent().find(".segmentFilter").val(self.translations['General_Search']).trigger('keyup');
});
self.target.on('blur', ".segmentFilter", function (e) {
if ($(e.target).parent().find(".segmentFilter").val() == "") {
$(e.target).parent().find(".segmentFilter").val(self.translations['General_Search'])
}
});
self.target.on('click', ".segmentFilter", function (e) {
if ($(e.target).val() == self.translations['General_Search']) {
$(e.target).val("");
}
});
self.target.on('keyup', ".segmentFilter", function (e) {
var search = $(e.currentTarget).val();
if (search == self.translations['General_Search']) {
search = "";
}
if (search.length >= 2) {
clearTimeout(self.filterTimer);
self.filterAllowed = true;
self.filterTimer = setTimeout(function () {
filterSegmentList(search);
}, 500);
}
else {
self.filterTimer = false;
clearFilterSegmentList();
}
});
//
// segment editor form events
//
@ -436,10 +586,12 @@ Segmentation = (function($) {
self.target.on('blur', "input.edit_segment_name", function (e) {
var newName = $(this).val();
if(newName.trim() != '') {
$(e.currentTarget).parents("h3").find("span").text(newName).show();
$(self.form).find("a.editSegmentName").show();
$(this).remove();
var segmentNameNode = $(e.currentTarget).parents("h3").find("span");
if(newName.trim()) {
segmentNameNode.text(newName);
} else {
$(this).val(segmentNameNode.text());
}
});
@ -529,29 +681,38 @@ Segmentation = (function($) {
// upon clicking - add new segment block, then bind 'x' action to newly added row
self.target.on('click', ".segment-add-row a", function(event, data){
$(self.form).find(".segment-and:last").after(getAndDiv()).after(getMockedFormRow());
var mockedRow = getMockedFormRow();
$(self.form).find(".segment-and:last").after(getAndDiv()).after(mockedRow);
if(typeof data !== "undefined"){
$(self.form).find(".metricList:last").val(data);
}
$(self.form).find(".metricList:last").trigger('change');
preselectFirstMetricMatch(mockedRow);
doDragDropBindings();
});
self.target.on("click", ".segment-add-row span", function(event, data){
if(typeof data !== "undefined") {
$(self.form).find(".segment-and:last").after(getAndDiv()).after(getMockedFormRow());
var mockedRow = getMockedFormRow();
$(self.form).find(".segment-and:last").after(getAndDiv()).after(mockedRow);
preselectFirstMetricMatch(mockedRow);
$(self.form).find(".metricList:last").val(data).trigger('change');
doDragDropBindings();
}
});
// add new OR block
self.target.on("click", ".segment-add-or a", function(event, data){
$(event.currentTarget).parents(".segment-rows").find(".segment-or:last").after(getOrDiv()).after(getMockedInputRowHtml());
self.target.on("click", ".segment-add-or a", function(event, data){
var parentRows = $(event.currentTarget).parents(".segment-rows");
parentRows.find(".segment-or:last").after(getOrDiv()).after(getMockedInputRowHtml());
if(typeof data !== "undefined"){
$(event.currentTarget).parents(".segment-rows").find(".metricList:last").val(data);
parentRows.find(".metricList:last").val(data);
}
$(event.currentTarget).parents(".segment-rows").find(".metricList:last").trigger('change');
parentRows.find(".metricList:last").trigger('change');
var addedRow = parentRows.find('.segment-row:last');
preselectFirstMetricMatch(addedRow);
doDragDropBindings();
});
@ -591,6 +752,15 @@ Segmentation = (function($) {
segmentName: segmentName
}, 'GET');
ajaxHandler.useRegularCallbackInCaseOfError = true;
ajaxHandler.setTimeout(20000);
ajaxHandler.setErrorCallback(function(response) {
loadingElement.hide();
inputElement.autocomplete({
source: [],
minLength: 0
});
$(inputElement).autocomplete('search', $(inputElement).val());
});
ajaxHandler.setCallback(function(response) {
loadingElement.hide();
@ -633,7 +803,12 @@ Segmentation = (function($) {
}
matchSelector.append(optionsHtml);
matchSelector.val(oldMatch);
if (matchSelector.find('option[value="' + oldMatch + '"]').length) {
matchSelector.val(oldMatch);
} else {
preselectFirstMetricMatch(matchSelector.parent());
}
};
var getAddNewBlockButtonHtml = function()
@ -664,20 +839,15 @@ Segmentation = (function($) {
};
function openEditFormGivenSegment(option) {
var segment = {};
segment.idsegment = option.attr("data-idsegment");
var idsegment = option.attr("data-idsegment");
var segmentExtra = getSegmentFromId(segment.idsegment);
for(var item in segmentExtra)
{
segment[item] = segmentExtra[item];
if(idsegment.length == 0) {
displayFormAddNewSegment();
} else {
var segment = getSegmentFromId(idsegment);
segment.definition = option.data("definition");
openEditForm(segment);
}
segment.name = option.attr("title");
segment.definition = option.data("definition");
openEditForm(segment);
}
var doDragDropBindings = function(){
@ -731,7 +901,7 @@ Segmentation = (function($) {
// 1 - do most obvious selection -> mark whole categories matching search string
// also expand whole category
$(self.form).find('.segment-nav div > ul > li').each( function(){
curStr = normalizeSearchString($(this).find("a.metric_category").text());
curStr = normalizeSearchString($(this).find("a.metric_category").text());
if(curStr.indexOf(search) > -1) {
$(this).addClass("searchFound");
$(this).find("ul").show();
@ -739,7 +909,7 @@ Segmentation = (function($) {
$(this).show();
}
}
);
);
// 2 - among all unselected categories find metrics which match and mark parent as search result
$(self.form).find(".segment-nav div > ul > li:not(.searchFound)").each(function(){
@ -788,8 +958,8 @@ Segmentation = (function($) {
}
search = search.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
.replace(/\s+/g, '_') // collapse whitespace and replace by underscore
.replace(/-+/g, '-'); // collapse dashes
.replace(/\s+/g, '_') // collapse whitespace and replace by underscore
.replace(/-+/g, '-'); // collapse dashes
return search;
};
@ -816,7 +986,12 @@ Segmentation = (function($) {
placeSegmentationFormControls();
if(mode == "edit") {
$(self.form).find('.enable_all_users_select > option[value="'+segment.enable_all_users+'"]').prop("selected",true);
var userSelector = $(self.form).find('.enable_all_users_select > option[value="' + segment.enable_all_users + '"]').prop("selected",true);
// Replace "Visible to me" by "Visible to $login" when user is super user
if(hasSuperUserAccessAndSegmentCreatedByAnotherUser(segment)) {
$(self.form).find('.enable_all_users_select > option[value="' + 0 + '"]').text(segment.login);
}
$(self.form).find('.visible_to_website_select > option[value="'+segment.enable_only_idsite+'"]').prop("selected",true);
$(self.form).find('.auto_archive_select > option[value="'+segment.auto_archive+'"]').prop("selected",true);
@ -849,7 +1024,7 @@ Segmentation = (function($) {
};
var closeForm = function () {
self.form.unbind().remove();
$(self.form).unbind().remove();
self.target.closest('.segmentEditorPanel').removeClass('editing');
};
@ -907,43 +1082,43 @@ Segmentation = (function($) {
var makeDropList = function(spanId, selectId){
var select = $(self.form).find(selectId).hide();
var dropList = $( '<a class="dropList dropdown">' )
.insertAfter( select )
.text( select.children(':selected').text() )
.autocomplete({
delay: 0,
minLength: 0,
appendTo: "body",
source: function( request, response ) {
response( select.children( "option" ).map(function() {
var text = $( this ).text();
return {
label: text,
value: this.value,
option: this
};
}) );
},
select: function( event, ui ) {
event.preventDefault();
ui.item.option.selected = true;
// Mark original select>option
$(spanId + ' option[value="' + ui.item.value + '"]', self.editorTemplate).prop('selected', true);
dropList.text(ui.item.label);
$(self.form).find(selectId).trigger("change");
}
})
.click(function() {
// close all other droplists made by this form
$("a.dropList").autocomplete("close");
// close if already visible
if ( $(this).autocomplete( "widget" ).is(":visible") ) {
$(this).autocomplete("close");
return;
}
// pass empty string as value to search for, displaying all results
$(this).autocomplete( "search", "" );
.insertAfter( select )
.text( select.children(':selected').text() )
.autocomplete({
delay: 0,
minLength: 0,
appendTo: "body",
source: function( request, response ) {
response( select.children( "option" ).map(function() {
var text = $( this ).text();
return {
label: text,
value: this.value,
option: this
};
}) );
},
select: function( event, ui ) {
event.preventDefault();
ui.item.option.selected = true;
// Mark original select>option
$(spanId + ' option[value="' + ui.item.value + '"]', self.editorTemplate).prop('selected', true);
dropList.text(ui.item.label);
$(self.form).find(selectId).trigger("change");
}
})
.click(function() {
// close all other droplists made by this form
$("a.dropList").autocomplete("close");
// close if already visible
if ( $(this).autocomplete( "widget" ).is(":visible") ) {
$(this).autocomplete("close");
return;
}
// pass empty string as value to search for, displaying all results
$(this).autocomplete( "search", "" );
});
});
$('body').on('mouseup',function (e) {
if (!$(e.target).parents(spanId).length
&& !$(e.target).is(spanId)
@ -990,14 +1165,13 @@ Segmentation = (function($) {
return segmentation;
})(jQuery);
$(document).ready(function() {
var exports = require('piwik/UI');
var UIControl = exports.UIControl;
/**
* Sets up and handles events for the segment selector & editor control.
*
*
* @param {Element} element The HTML element generated by the SegmentSelectorControl PHP class. Should
* have the CSS class 'segmentEditorPanel'.
* @constructor
@ -1023,7 +1197,7 @@ $(document).ready(function() {
this.changeSegmentList = function () {};
var cleanupSegmentDefinition = function(definition) {
definition = definition.replace("'", "%29");
definition = definition.replace("'", "%27");
definition = definition.replace("&", "%26");
return definition;
};
@ -1083,7 +1257,7 @@ $(document).ready(function() {
}
}
self.props.availableSegments[idx] = params;
$.extend( self.props.availableSegments[idx], params);
self.rebuild();
self.impl.setSegment(params.definition);
@ -1098,7 +1272,6 @@ $(document).ready(function() {
ajaxHandler.send(true);
};
var deleteSegment = function(params){
var ajaxHandler = new ajaxHelper();
ajaxHandler.addParams({
@ -1140,16 +1313,18 @@ $(document).ready(function() {
};
var segmentFromRequest = encodeURIComponent(self.props.selectedSegment)
|| broadcast.getValueFromHash('segment')
|| broadcast.getValueFromUrl('segment');
|| broadcast.getValueFromHash('segment')
|| broadcast.getValueFromUrl('segment');
if($.browser.mozilla) {
segmentFromRequest = decodeURIComponent(segmentFromRequest);
}
var userSegmentAccess = (this.props.authorizedToCreateSegments) ? "write" : "read";
this.impl = new Segmentation({
"target" : this.$element.find(".segmentListContainer"),
"editorTemplate": $('.SegmentEditor', self.$element),
"segmentAccess" : "write",
"segmentAccess" : userSegmentAccess,
"availableSegments" : this.props.availableSegments,
"addMethod": addSegment,
"updateMethod": updateSegment,
@ -1170,7 +1345,7 @@ $(document).ready(function() {
}
if ($(e.target).closest('.segmentListContainer').length === 0
&& self.$element.hasClass("visible")
&& self.$element.hasClass("expanded")
) {
$(".segmentationContainer", self.$element).trigger("click");
}
@ -1178,8 +1353,6 @@ $(document).ready(function() {
$('body').on('mouseup', this.onMouseUp);
// re-initialize top controls since the size of the control is not the same after it's
// initialized.
initTopControls();
};
@ -1213,4 +1386,4 @@ $(document).ready(function() {
});
exports.SegmentSelectorControl = SegmentSelectorControl;
});
});