mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-02-03 20:09:27 +01:00
fixed error, if no favorites are defined
This commit is contained in:
parent
54c930b555
commit
96336ea521
@ -20,7 +20,7 @@
|
|||||||
/**
|
/**
|
||||||
* Favorites widget, designed for use with a nextmatch widget
|
* Favorites widget, designed for use with a nextmatch widget
|
||||||
*
|
*
|
||||||
* The primary control is a split/dropdown button. Clicking on the left side of the button filters the
|
* The primary control is a split/dropdown button. Clicking on the left side of the button filters the
|
||||||
* nextmatch list by the user's default filter. The right side of the button gives a list of
|
* nextmatch list by the user's default filter. The right side of the button gives a list of
|
||||||
* saved filters, pulled from preferences. Clicking a filter from the dropdown list sets the
|
* saved filters, pulled from preferences. Clicking a filter from the dropdown list sets the
|
||||||
* filters as saved.
|
* filters as saved.
|
||||||
@ -28,7 +28,7 @@
|
|||||||
* Favorites can also automatically be shown in the sidebox, using the special ID favorite_sidebox.
|
* Favorites can also automatically be shown in the sidebox, using the special ID favorite_sidebox.
|
||||||
* Use the following code to generate the sidebox section:
|
* Use the following code to generate the sidebox section:
|
||||||
* display_sidebox($appname,lang('Favorites'),array(
|
* display_sidebox($appname,lang('Favorites'),array(
|
||||||
* array(
|
* array(
|
||||||
* 'no_lang' => true,
|
* 'no_lang' => true,
|
||||||
* 'text'=>'<span id="favorite_sidebox"/>',
|
* 'text'=>'<span id="favorite_sidebox"/>',
|
||||||
* 'link'=>false,
|
* 'link'=>false,
|
||||||
@ -41,7 +41,7 @@
|
|||||||
* Favorites are implemented by saving the values for [column] filters. Filters are stored
|
* Favorites are implemented by saving the values for [column] filters. Filters are stored
|
||||||
* in preferences, with the name favorite_<name>. The favorite favorite used for clicking on
|
* in preferences, with the name favorite_<name>. The favorite favorite used for clicking on
|
||||||
* the filter button is stored in nextmatch-<columnselection_pref>-favorite.
|
* the filter button is stored in nextmatch-<columnselection_pref>-favorite.
|
||||||
*
|
*
|
||||||
* @augments et2_dropdown_button
|
* @augments et2_dropdown_button
|
||||||
*/
|
*/
|
||||||
var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
||||||
@ -88,7 +88,7 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @memberOf et2_favorites
|
* @memberOf et2_favorites
|
||||||
*/
|
*/
|
||||||
init: function() {
|
init: function() {
|
||||||
@ -113,7 +113,7 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
|
|
||||||
// It helps to have the ID properly set before we get too far
|
// It helps to have the ID properly set before we get too far
|
||||||
this.set_id(this.id);
|
this.set_id(this.id);
|
||||||
|
|
||||||
this.init_filters(this);
|
this.init_filters(this);
|
||||||
|
|
||||||
this.menu.addClass("favorites");
|
this.menu.addClass("favorites");
|
||||||
@ -126,7 +126,7 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
{
|
{
|
||||||
this.set_value(this.options.value);
|
this.set_value(this.options.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// Initialize sidebox
|
// Initialize sidebox
|
||||||
@ -136,7 +136,7 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
$j(this.menu).on("click","input:radio", function(event){
|
$j(this.menu).on("click","input:radio", function(event){
|
||||||
// Don't do the menu
|
// Don't do the menu
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
|
|
||||||
// Save as default favorite - used when you click the button
|
// Save as default favorite - used when you click the button
|
||||||
self.egw().set_preference(self.options.app,self.options.default_pref,$j(this).val());
|
self.egw().set_preference(self.options.app,self.options.default_pref,$j(this).val());
|
||||||
self.preferred = $j(this).val();
|
self.preferred = $j(this).val();
|
||||||
@ -148,7 +148,7 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
.replaceWith("<img class='sideboxstar'/>");
|
.replaceWith("<img class='sideboxstar'/>");
|
||||||
$j("li[data-id='"+self.preferred+"'] img",self.sidebox_target)
|
$j("li[data-id='"+self.preferred+"'] img",self.sidebox_target)
|
||||||
.replaceWith("<div class='ui-icon ui-icon-heart'/>");
|
.replaceWith("<div class='ui-icon ui-icon-heart'/>");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the menu
|
// Close the menu
|
||||||
@ -282,9 +282,9 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
var options = {};
|
var options = {};
|
||||||
for(var name in filters)
|
for(var name in filters)
|
||||||
{
|
{
|
||||||
options[name] = "<input type='radio' name='"+this.internal_ids.menu+"[button][favorite]' value='"+name+"' title='" +
|
options[name] = "<input type='radio' name='"+this.internal_ids.menu+"[button][favorite]' value='"+name+"' title='" +
|
||||||
this.egw().lang('Set as default') + "'/>"+
|
this.egw().lang('Set as default') + "'/>"+
|
||||||
(filters[name].name != undefined ? filters[name].name : name) +
|
(filters[name].name != undefined ? filters[name].name : name) +
|
||||||
(filters[name].group != false ? " ♦" :"") +
|
(filters[name].group != false ? " ♦" :"") +
|
||||||
(filters[name].group != false && !this.is_admin || name == 'blank' ? "" :
|
(filters[name].group != false && !this.is_admin || name == 'blank' ? "" :
|
||||||
"<div class='ui-icon ui-icon-trash' title='" + this.egw().lang('Delete') + "'/>");
|
"<div class='ui-icon ui-icon-trash' title='" + this.egw().lang('Delete') + "'/>");
|
||||||
@ -317,14 +317,14 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find sidebox, if not found yet, and register handlers
|
* Find sidebox, if not found yet, and register handlers
|
||||||
*/
|
*/
|
||||||
_init_sidebox: function()
|
_init_sidebox: function()
|
||||||
{
|
{
|
||||||
// Sometimes the sidebox is not loaded when the template is created (jdots)
|
// Sometimes the sidebox is not loaded when the template is created (jdots)
|
||||||
if(!this.sidebox_target || this.sidebox_target.length == 0)
|
if(this.options && (!this.sidebox_target || this.sidebox_target.length == 0))
|
||||||
{
|
{
|
||||||
this.sidebox_target = $j("#"+this.options.sidebox_target);
|
this.sidebox_target = $j("#"+this.options.sidebox_target);
|
||||||
if(this.sidebox_target.length == 0 && egw_getFramework() != null)
|
if(this.sidebox_target.length == 0 && egw_getFramework() != null)
|
||||||
@ -335,7 +335,7 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
if(this.sidebox_target.length == 0)
|
if(this.sidebox_target.length == 0)
|
||||||
{
|
{
|
||||||
// Still no sidebox - might be loaded via ajax later, so we'll do this on first mouse over
|
// Still no sidebox - might be loaded via ajax later, so we'll do this on first mouse over
|
||||||
$j('body').on('mouseover','#'+this.options.sidebox_target,
|
$j('body').on('mouseover','#'+this.options.sidebox_target,
|
||||||
jQuery.proxy(function(e) {
|
jQuery.proxy(function(e) {
|
||||||
// Set up handlers & such
|
// Set up handlers & such
|
||||||
this._init_sidebox();
|
this._init_sidebox();
|
||||||
@ -361,7 +361,7 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
set_nm_filters: function(filters)
|
set_nm_filters: function(filters)
|
||||||
{
|
{
|
||||||
if(this.nextmatch)
|
if(this.nextmatch)
|
||||||
@ -387,7 +387,7 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// Apply the favorite when you pick from the list
|
// Apply the favorite when you pick from the list
|
||||||
change: function(selected_node) {
|
change: function(selected_node) {
|
||||||
this.value = $j(selected_node).attr("data-id");
|
this.value = $j(selected_node).attr("data-id");
|
||||||
@ -407,7 +407,7 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
this.popup.current_filters[this.options.filters[i]] = this.nextmatch.options.settings[this.options.filters[i]];
|
this.popup.current_filters[this.options.filters[i]] = this.nextmatch.options.settings[this.options.filters[i]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove some internal values
|
// Remove some internal values
|
||||||
delete this.popup.current_filters[this.id];
|
delete this.popup.current_filters[this.id];
|
||||||
if(this.popup.group != undefined)
|
if(this.popup.group != undefined)
|
||||||
@ -423,7 +423,7 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
var add_to_popup = function(arr) {
|
var add_to_popup = function(arr) {
|
||||||
filter_list.push("<ul>");
|
filter_list.push("<ul>");
|
||||||
jQuery.each(arr, function(index, filter) {
|
jQuery.each(arr, function(index, filter) {
|
||||||
filter_list.push("<li id='index'><span class='filter_id'>"+index+"</span>" +
|
filter_list.push("<li id='index'><span class='filter_id'>"+index+"</span>" +
|
||||||
(typeof filter != "object" ? "<span class='filter_value'>"+filter+"</span>": "")
|
(typeof filter != "object" ? "<span class='filter_value'>"+filter+"</span>": "")
|
||||||
);
|
);
|
||||||
if(typeof filter == "object" && filter != null) add_to_popup(filter);
|
if(typeof filter == "object" && filter != null) add_to_popup(filter);
|
||||||
@ -440,7 +440,7 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
.hide()
|
.hide()
|
||||||
.siblings(".ui-icon-circle-plus")
|
.siblings(".ui-icon-circle-plus")
|
||||||
.removeClass("ui-icon-circle-minus");
|
.removeClass("ui-icon-circle-minus");
|
||||||
|
|
||||||
// Popup
|
// Popup
|
||||||
this.popup.dialog("open");
|
this.popup.dialog("open");
|
||||||
|
|
||||||
@ -463,13 +463,13 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
this.popup.group.free();
|
this.popup.group.free();
|
||||||
delete this.popup;
|
delete this.popup;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create popup
|
// Create popup
|
||||||
this.popup = $j('<div id="'+this.dom_id + '_nm_favorites_popup" title="' + egw().lang("New favorite") + '">\
|
this.popup = $j('<div id="'+this.dom_id + '_nm_favorites_popup" title="' + egw().lang("New favorite") + '">\
|
||||||
<form>\
|
<form>\
|
||||||
<label for="name">'+
|
<label for="name">'+
|
||||||
this.egw().lang("name") +
|
this.egw().lang("name") +
|
||||||
'</label>' +
|
'</label>' +
|
||||||
|
|
||||||
'<input type="text" name="name" id="name"/>\
|
'<input type="text" name="name" id="name"/>\
|
||||||
<div id="'+this.dom_id+'nm_favorites_popup_admin"/>\
|
<div id="'+this.dom_id+'nm_favorites_popup_admin"/>\
|
||||||
@ -511,7 +511,7 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
var safe_name = name.val().replace(/[^A-Za-z0-9-_]/g,"_");
|
var safe_name = name.val().replace(/[^A-Za-z0-9-_]/g,"_");
|
||||||
self.stored_filters[safe_name] = {
|
self.stored_filters[safe_name] = {
|
||||||
name: name.val(),
|
name: name.val(),
|
||||||
group: (typeof self.popup.group != "undefined" &&
|
group: (typeof self.popup.group != "undefined" &&
|
||||||
self.popup.group.get_value() ? self.popup.group.get_value() : false),
|
self.popup.group.get_value() ? self.popup.group.get_value() : false),
|
||||||
filter: self.popup.current_filters
|
filter: self.popup.current_filters
|
||||||
};
|
};
|
||||||
@ -556,7 +556,7 @@ var et2_favorites = et2_dropdown_button.extend([et2_INextmatchHeader],
|
|||||||
self.popup.group.set_value(null);
|
self.popup.group.set_value(null);
|
||||||
$j(this).dialog("close");
|
$j(this).dialog("close");
|
||||||
};
|
};
|
||||||
|
|
||||||
this.popup.dialog({
|
this.popup.dialog({
|
||||||
autoOpen: false,
|
autoOpen: false,
|
||||||
modal: true,
|
modal: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user