mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 14:41:29 +01:00
Calendar to TS working
This commit is contained in:
parent
0f898acbb2
commit
08b6cce51d
4144
calendar/js/app.ts
Normal file
4144
calendar/js/app.ts
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Egroupware
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
@ -7,12 +8,24 @@
|
||||
* @author Nathan Gray
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/*egw:uses
|
||||
et2_widget_taglist;
|
||||
*/
|
||||
|
||||
var et2_core_widget_1 = require("../../api/js/etemplate/et2_core_widget");
|
||||
/**
|
||||
* Tag list widget customised for calendar owner, which can be a user
|
||||
* account or group, or an entry from almost any app, or an email address
|
||||
@ -23,9 +36,86 @@
|
||||
* @see http://nicolasbize.github.io/magicsuggest/
|
||||
* @augments et2_selectbox
|
||||
*/
|
||||
var et2_calendar_owner = (function(){ "use strict"; return et2_taglist_email.extend(
|
||||
{
|
||||
attributes: {
|
||||
var et2_calendar_owner = /** @class */ (function (_super) {
|
||||
__extends(et2_calendar_owner, _super);
|
||||
function et2_calendar_owner() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
// Allows sub-widgets to override options to the library
|
||||
_this.lib_options = {
|
||||
autoSelect: false,
|
||||
groupBy: 'app',
|
||||
minChars: 2,
|
||||
selectFirst: true,
|
||||
// This option will also expand when the selection is changed
|
||||
// via code, which we do not want
|
||||
//expandOnFocus: true
|
||||
toggleOnClick: true
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
et2_calendar_owner.prototype.doLoadingFinished = function () {
|
||||
_super.prototype.doLoadingFinished.call(this);
|
||||
var widget = this;
|
||||
// onChange fired when losing focus, which is different from normal
|
||||
this._oldValue = this.taglist.getValue();
|
||||
return true;
|
||||
};
|
||||
et2_calendar_owner.prototype.selectionRenderer = function (item) {
|
||||
if (this && this.options && this.options.allowFreeEntries) {
|
||||
return _super.prototype.selectionRenderer.call(this, item);
|
||||
}
|
||||
else {
|
||||
var label = jQuery('<span>').text(item.label);
|
||||
if (item.class)
|
||||
label.addClass(item.class);
|
||||
if (typeof item.title != 'undefined')
|
||||
label.attr('title', item.title);
|
||||
if (typeof item.data != 'undefined')
|
||||
label.attr('data', item.data);
|
||||
if (typeof item.icon != 'undefined') {
|
||||
var wrapper = jQuery('<div>').addClass('et2_taglist_tags_icon_wrapper');
|
||||
jQuery('<span/>')
|
||||
.addClass('et2_taglist_tags_icon')
|
||||
.css({ "background-image": "url(" + (item.icon.match(/^(http|https|\/)/) ? item.icon : egw.image(item.icon, item.app)) + ")" })
|
||||
.appendTo(wrapper);
|
||||
label.appendTo(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
return label;
|
||||
}
|
||||
};
|
||||
et2_calendar_owner.prototype.getValue = function () {
|
||||
if (this.taglist == null)
|
||||
return null;
|
||||
return this.taglist.getValue();
|
||||
};
|
||||
/**
|
||||
* Override parent to handle our special additional data types (c#,r#,etc.) when they
|
||||
* are not available client side.
|
||||
*
|
||||
* @param {string|string[]} _value array of selected owners, which can be a number,
|
||||
* or a number prefixed with one character indicating the resource type.
|
||||
*/
|
||||
et2_calendar_owner.prototype.set_value = function (_value) {
|
||||
_super.prototype.set_value.call(this, _value);
|
||||
// If parent didn't find a label, label will be the same as ID so we
|
||||
// can find them that way
|
||||
for (var i = 0; i < this.options.value.length; i++) {
|
||||
var value = this.options.value[i];
|
||||
if (value.id == value.label) {
|
||||
// Proper label was not fount by parent - ask directly
|
||||
egw.json('calendar_owner_etemplate_widget::ajax_owner', value.id, function (data) {
|
||||
this.widget.options.value[this.i].label = data;
|
||||
this.widget.set_value(this.widget.options.value);
|
||||
}, this, true, { widget: this, i: i }).sendRequest();
|
||||
}
|
||||
}
|
||||
if (this.taglist) {
|
||||
this.taglist.clear(true);
|
||||
this.taglist.addToSelection(this.options.value, true);
|
||||
}
|
||||
};
|
||||
et2_calendar_owner._attributes = {
|
||||
"autocomplete_url": {
|
||||
"default": "calendar_owner_etemplate_widget::ajax_owner"
|
||||
},
|
||||
@ -46,94 +136,9 @@ var et2_calendar_owner = (function(){ "use strict"; return et2_taglist_email.ext
|
||||
"default": {},
|
||||
"description": "Internally used to hold the select options."
|
||||
}
|
||||
},
|
||||
|
||||
// Allows sub-widgets to override options to the library
|
||||
lib_options: {
|
||||
autoSelect: false,
|
||||
groupBy: 'app',
|
||||
minChars: 2,
|
||||
selectFirst: true,
|
||||
// This option will also expand when the selection is changed
|
||||
// via code, which we do not want
|
||||
//expandOnFocus: true
|
||||
toggleOnClick: true
|
||||
},
|
||||
|
||||
|
||||
doLoadingFinished: function() {
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
var widget = this;
|
||||
// onChange fired when losing focus, which is different from normal
|
||||
this._oldValue = this.taglist.getValue();
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
selectionRenderer: function(item)
|
||||
{
|
||||
if(this && this.options && this.options.allowFreeEntries)
|
||||
{
|
||||
return this._super.apply(this,arguments);
|
||||
}
|
||||
else
|
||||
{
|
||||
var label = jQuery('<span>').text(item.label);
|
||||
if (item.class) label.addClass(item.class);
|
||||
if (typeof item.title != 'undefined') label.attr('title', item.title);
|
||||
if (typeof item.data != 'undefined') label.attr('data', item.data);
|
||||
if (typeof item.icon != 'undefined')
|
||||
{
|
||||
var wrapper = jQuery('<div>').addClass('et2_taglist_tags_icon_wrapper');
|
||||
jQuery('<span/>')
|
||||
.addClass('et2_taglist_tags_icon')
|
||||
.css({"background-image": "url("+(item.icon.match(/^(http|https|\/)/) ? item.icon : egw.image(item.icon, item.app))+")"})
|
||||
.appendTo(wrapper);
|
||||
label.appendTo(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
return label;
|
||||
}
|
||||
},
|
||||
|
||||
getValue: function()
|
||||
{
|
||||
if(this.taglist == null) return null;
|
||||
return this.taglist.getValue();
|
||||
},
|
||||
|
||||
/**
|
||||
* Override parent to handle our special additional data types (c#,r#,etc.) when they
|
||||
* are not available client side.
|
||||
*
|
||||
* @param {string|string[]} _value array of selected owners, which can be a number,
|
||||
* or a number prefixed with one character indicating the resource type.
|
||||
*/
|
||||
set_value: function(_value)
|
||||
{
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
// If parent didn't find a label, label will be the same as ID so we
|
||||
// can find them that way
|
||||
for(var i = 0; i < this.options.value.length; i++)
|
||||
{
|
||||
var value = this.options.value[i];
|
||||
if(value.id == value.label)
|
||||
{
|
||||
// Proper label was not fount by parent - ask directly
|
||||
egw.json('calendar_owner_etemplate_widget::ajax_owner',value.id,function(data) {
|
||||
this.widget.options.value[this.i].label = data;
|
||||
this.widget.set_value(this.widget.options.value);
|
||||
}, this,true,{widget: this, i: i}).sendRequest();
|
||||
}
|
||||
}
|
||||
|
||||
if(this.taglist)
|
||||
{
|
||||
this.taglist.clear(true);
|
||||
this.taglist.addToSelection(this.options.value,true);
|
||||
}
|
||||
}
|
||||
});}).call(this);
|
||||
et2_register_widget(et2_calendar_owner, ["calendar-owner"]);
|
||||
};
|
||||
return et2_calendar_owner;
|
||||
}(et2_taglist_email));
|
||||
exports.et2_calendar_owner = et2_calendar_owner;
|
||||
et2_core_widget_1.et2_register_widget(et2_calendar_owner, ["calendar-owner"]);
|
||||
//# sourceMappingURL=et2_widget_owner.js.map
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Egroupware
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
@ -7,11 +8,22 @@
|
||||
* @author Nathan Gray
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/*egw:uses
|
||||
/etemplate/js/et2_core_valueWidget;
|
||||
*/
|
||||
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var et2_core_valueWidget_1 = require("../../api/js/etemplate/et2_core_valueWidget");
|
||||
var et2_core_inheritance_1 = require("../../api/js/etemplate/et2_core_inheritance");
|
||||
/**
|
||||
* Parent class for the various calendar views to reduce copied code
|
||||
*
|
||||
@ -21,72 +33,49 @@
|
||||
*
|
||||
* @augments et2_valueWidget
|
||||
*/
|
||||
var et2_calendar_view = (function(){ "use strict"; return et2_valueWidget.extend(
|
||||
{
|
||||
createNamespace: true,
|
||||
|
||||
attributes: {
|
||||
owner: {
|
||||
name: "Owner",
|
||||
type: "any", // Integer, or array of integers, or string like r13 (resources, addressbook)
|
||||
default: [egw.user('account_id')],
|
||||
description: "Account ID number of the calendar owner, if not the current user"
|
||||
},
|
||||
start_date: {
|
||||
name: "Start date",
|
||||
type: "any"
|
||||
},
|
||||
end_date: {
|
||||
name: "End date",
|
||||
type: "any"
|
||||
}
|
||||
},
|
||||
|
||||
var et2_calendar_view = /** @class */ (function (_super) {
|
||||
__extends(et2_calendar_view, _super);
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @memberOf et2_calendar_view
|
||||
* @constructor
|
||||
*/
|
||||
init: function init() {
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
function et2_calendar_view(_parent, _attrs, _child) {
|
||||
var _this =
|
||||
// Call the inherited constructor
|
||||
_super.call(this, _parent, _attrs, et2_core_inheritance_1.ClassWithAttributes.extendAttributes(et2_calendar_view._attributes, _child || {})) || this;
|
||||
_this.dataStorePrefix = 'calendar';
|
||||
_this.update_timer = null;
|
||||
// Used for its date calculations
|
||||
this.date_helper = et2_createWidget('date-time',{},null);
|
||||
this.date_helper.loadingFinished();
|
||||
|
||||
this.loader = jQuery('<div class="egw-loading-prompt-container ui-front loading"></div>');
|
||||
this.update_timer = null;
|
||||
|
||||
_this._date_helper = et2_createWidget('date-time', {}, null);
|
||||
_this._date_helper.loadingFinished();
|
||||
_this.loader = jQuery('<div class="egw-loading-prompt-container ui-front loading"></div>');
|
||||
_this.update_timer = null;
|
||||
// Used to support dragging on empty space to create an event
|
||||
this.drag_create = {
|
||||
_this.drag_create = {
|
||||
start: null,
|
||||
end: null,
|
||||
parent: null,
|
||||
event: null
|
||||
};
|
||||
},
|
||||
|
||||
destroy: function destroy() {
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
return _this;
|
||||
}
|
||||
et2_calendar_view.prototype.destroy = function () {
|
||||
_super.prototype.destroy.call(this);
|
||||
// date_helper has no parent, so we must explicitly remove it
|
||||
this.date_helper.destroy();
|
||||
this.date_helper = null;
|
||||
|
||||
this._date_helper.destroy();
|
||||
this._date_helper = null;
|
||||
// Stop the invalidate timer
|
||||
if(this.update_timer)
|
||||
{
|
||||
if (this.update_timer) {
|
||||
window.clearTimeout(this.update_timer);
|
||||
}
|
||||
},
|
||||
|
||||
doLoadingFinished: function() {
|
||||
this._super.apply(this, arguments);
|
||||
};
|
||||
et2_calendar_view.prototype.doLoadingFinished = function () {
|
||||
_super.prototype.doLoadingFinished.call(this);
|
||||
this.loader.hide(0).prependTo(this.div);
|
||||
if(this.options.owner) this.set_owner(this.options.owner);
|
||||
},
|
||||
|
||||
if (this.options.owner)
|
||||
this.set_owner(this.options.owner);
|
||||
return true;
|
||||
};
|
||||
/**
|
||||
* Something changed, and the view need to be re-drawn. We wait a bit to
|
||||
* avoid re-drawing twice if start and end date both changed, then recreate
|
||||
@ -98,10 +87,9 @@ var et2_calendar_view = (function(){ "use strict"; return et2_valueWidget.extend
|
||||
*
|
||||
* @memberOf et2_calendar_view
|
||||
*/
|
||||
invalidate: function invalidate(trigger_event) {
|
||||
et2_calendar_view.prototype.invalidate = function (trigger_event) {
|
||||
// If this wasn't a stub, we'd set this.update_timer
|
||||
},
|
||||
|
||||
};
|
||||
/**
|
||||
* Returns the current start date
|
||||
*
|
||||
@ -109,10 +97,9 @@ var et2_calendar_view = (function(){ "use strict"; return et2_valueWidget.extend
|
||||
*
|
||||
* @memberOf et2_calendar_view
|
||||
*/
|
||||
get_start_date: function get_start_date() {
|
||||
et2_calendar_view.prototype.get_start_date = function () {
|
||||
return new Date(this.options.start_date);
|
||||
},
|
||||
|
||||
};
|
||||
/**
|
||||
* Returns the current start date
|
||||
*
|
||||
@ -120,10 +107,9 @@ var et2_calendar_view = (function(){ "use strict"; return et2_valueWidget.extend
|
||||
*
|
||||
* @memberOf et2_calendar_view
|
||||
*/
|
||||
get_end_date: function get_end_date() {
|
||||
et2_calendar_view.prototype.get_end_date = function () {
|
||||
return new Date(this.options.end_date);
|
||||
},
|
||||
|
||||
};
|
||||
/**
|
||||
* Change the start date
|
||||
*
|
||||
@ -136,36 +122,27 @@ var et2_calendar_view = (function(){ "use strict"; return et2_valueWidget.extend
|
||||
*
|
||||
* @memberOf et2_calendar_view
|
||||
*/
|
||||
set_start_date: function set_start_date(new_date)
|
||||
{
|
||||
if(!new_date || new_date === null)
|
||||
{
|
||||
et2_calendar_view.prototype.set_start_date = function (new_date) {
|
||||
if (!new_date || new_date === null) {
|
||||
new_date = new Date();
|
||||
}
|
||||
|
||||
// Use date widget's existing functions to deal
|
||||
if(typeof new_date === "object" || typeof new_date === "string" && new_date.length > 8)
|
||||
{
|
||||
this.date_helper.set_value(new_date);
|
||||
if (typeof new_date === "object" || typeof new_date === "string" && new_date.length > 8) {
|
||||
this._date_helper.set_value(new_date);
|
||||
}
|
||||
else if(typeof new_date === "string")
|
||||
{
|
||||
this.date_helper.set_year(new_date.substring(0,4));
|
||||
else if (typeof new_date === "string") {
|
||||
this._date_helper.set_year(new_date.substring(0, 4));
|
||||
// Avoid overflow into next month, since we re-use date_helper
|
||||
this.date_helper.set_date(1);
|
||||
this.date_helper.set_month(new_date.substring(4,6));
|
||||
this.date_helper.set_date(new_date.substring(6,8));
|
||||
this._date_helper.set_date(1);
|
||||
this._date_helper.set_month(new_date.substring(4, 6));
|
||||
this._date_helper.set_date(new_date.substring(6, 8));
|
||||
}
|
||||
|
||||
var old_date = this.options.start_date;
|
||||
this.options.start_date = new Date(this.date_helper.getValue());
|
||||
|
||||
if(old_date !== this.options.start_date && this.isAttached())
|
||||
{
|
||||
this.options.start_date = new Date(this._date_helper.getValue());
|
||||
if (old_date !== this.options.start_date && this.isAttached()) {
|
||||
this.invalidate(true);
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
/**
|
||||
* Change the end date
|
||||
*
|
||||
@ -178,35 +155,27 @@ var et2_calendar_view = (function(){ "use strict"; return et2_valueWidget.extend
|
||||
*
|
||||
* @memberOf et2_calendar_view
|
||||
*/
|
||||
set_end_date: function set_end_date(new_date)
|
||||
{
|
||||
if(!new_date || new_date === null)
|
||||
{
|
||||
et2_calendar_view.prototype.set_end_date = function (new_date) {
|
||||
if (!new_date || new_date === null) {
|
||||
new_date = new Date();
|
||||
}
|
||||
// Use date widget's existing functions to deal
|
||||
if(typeof new_date === "object" || typeof new_date === "string" && new_date.length > 8)
|
||||
{
|
||||
this.date_helper.set_value(new_date);
|
||||
if (typeof new_date === "object" || typeof new_date === "string" && new_date.length > 8) {
|
||||
this._date_helper.set_value(new_date);
|
||||
}
|
||||
else if(typeof new_date === "string")
|
||||
{
|
||||
this.date_helper.set_year(new_date.substring(0,4));
|
||||
else if (typeof new_date === "string") {
|
||||
this._date_helper.set_year(new_date.substring(0, 4));
|
||||
// Avoid overflow into next month, since we re-use date_helper
|
||||
this.date_helper.set_date(1);
|
||||
this.date_helper.set_month(new_date.substring(4,6));
|
||||
this.date_helper.set_date(new_date.substring(6,8));
|
||||
this._date_helper.set_date(1);
|
||||
this._date_helper.set_month(new_date.substring(4, 6));
|
||||
this._date_helper.set_date(new_date.substring(6, 8));
|
||||
}
|
||||
|
||||
var old_date = this.options.end_date;
|
||||
this.options.end_date = new Date(this.date_helper.getValue());
|
||||
|
||||
if(old_date !== this.options.end_date && this.isAttached())
|
||||
{
|
||||
this.options.end_date = new Date(this._date_helper.getValue());
|
||||
if (old_date !== this.options.end_date && this.isAttached()) {
|
||||
this.invalidate(true);
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
/**
|
||||
* Set which users to display
|
||||
*
|
||||
@ -220,44 +189,33 @@ var et2_calendar_view = (function(){ "use strict"; return et2_valueWidget.extend
|
||||
*
|
||||
* @memberOf et2_calendar_view
|
||||
*/
|
||||
set_owner: function set_owner(_owner)
|
||||
{
|
||||
et2_calendar_view.prototype.set_owner = function (_owner) {
|
||||
var old = this.options.owner;
|
||||
|
||||
// 0 means current user, but that causes problems for comparison,
|
||||
// so we'll just switch to the actual ID
|
||||
if(_owner == '0')
|
||||
{
|
||||
if (_owner == '0') {
|
||||
_owner = [egw.user('account_id')];
|
||||
}
|
||||
if(!jQuery.isArray(_owner))
|
||||
{
|
||||
if(typeof _owner === "string")
|
||||
{
|
||||
if (!jQuery.isArray(_owner)) {
|
||||
if (typeof _owner === "string") {
|
||||
_owner = _owner.split(',');
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
_owner = [_owner];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_owner = jQuery.extend([],_owner);
|
||||
else {
|
||||
_owner = jQuery.extend([], _owner);
|
||||
}
|
||||
this.options.owner = _owner;
|
||||
if(this.isAttached() && (
|
||||
typeof old === "number" && typeof _owner === "number" && old !== this.options.owner ||
|
||||
if (this.isAttached() && (typeof old === "number" && typeof _owner === "number" && old !== this.options.owner ||
|
||||
// Array of ids will not compare as equal
|
||||
((typeof old === 'object' || typeof _owner === 'object') && old.toString() !== _owner.toString()) ||
|
||||
// Strings
|
||||
typeof old === 'string' && ''+old !== ''+this.options.owner
|
||||
))
|
||||
{
|
||||
typeof old === 'string' && '' + old !== '' + this.options.owner)) {
|
||||
this.invalidate(true);
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
/**
|
||||
* Provide specific data to be displayed.
|
||||
* This is a way to set start and end dates, owner and event data in one call.
|
||||
@ -276,46 +234,46 @@ var et2_calendar_view = (function(){ "use strict"; return et2_valueWidget.extend
|
||||
* necessarily an entry from the resource app), or a list containing a
|
||||
* combination of both.
|
||||
*/
|
||||
set_value: function set_value(events)
|
||||
{
|
||||
if(typeof events !== 'object') return false;
|
||||
|
||||
if(events.length && events.length > 0 || !jQuery.isEmptyObject(events))
|
||||
{
|
||||
et2_calendar_view.prototype.set_value = function (events) {
|
||||
if (typeof events !== 'object')
|
||||
return false;
|
||||
if (events.length && events.length > 0 || !jQuery.isEmptyObject(events)) {
|
||||
this.set_disabled(false);
|
||||
}
|
||||
if(events.id)
|
||||
{
|
||||
if (events.id) {
|
||||
this.set_id(events.id);
|
||||
delete events.id;
|
||||
}
|
||||
if(events.start_date)
|
||||
{
|
||||
if (events.start_date) {
|
||||
this.set_start_date(events.start_date);
|
||||
delete events.start_date;
|
||||
}
|
||||
if(events.end_date)
|
||||
{
|
||||
if (events.end_date) {
|
||||
this.set_end_date(events.end_date);
|
||||
delete events.end_date;
|
||||
}
|
||||
// set_owner() wants start_date set to get the correct week number
|
||||
// for the corner label
|
||||
if(events.owner)
|
||||
{
|
||||
if (events.owner) {
|
||||
this.set_owner(events.owner);
|
||||
delete events.owner;
|
||||
}
|
||||
|
||||
this.value = events || {};
|
||||
|
||||
// None of the above changed anything, hide the loader
|
||||
if(!this.update_timer)
|
||||
{
|
||||
window.setTimeout(jQuery.proxy(function() {this.loader.hide();},this),200);
|
||||
if (!this.update_timer) {
|
||||
window.setTimeout(jQuery.proxy(function () { this.loader.hide(); }, this), 200);
|
||||
}
|
||||
};
|
||||
Object.defineProperty(et2_calendar_view.prototype, "date_helper", {
|
||||
get: function () {
|
||||
return this._date_helper;
|
||||
},
|
||||
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
et2_calendar_view.prototype._createNamespace = function () {
|
||||
return true;
|
||||
};
|
||||
/**
|
||||
* Calendar supports many different owner types, including users & resources.
|
||||
* This translates an ID to a user-friendly name.
|
||||
@ -325,104 +283,81 @@ var et2_calendar_view = (function(){ "use strict"; return et2_valueWidget.extend
|
||||
*
|
||||
* @memberOf et2_calendar_view
|
||||
*/
|
||||
_get_owner_name: function _get_owner_name(user) {
|
||||
et2_calendar_view.prototype._get_owner_name = function (user) {
|
||||
var label = undefined;
|
||||
if(parseInt(user) === 0)
|
||||
{
|
||||
if (parseInt(user) === 0) {
|
||||
// 0 means current user
|
||||
user = egw.user('account_id');
|
||||
}
|
||||
if(et2_calendar_view.owner_name_cache[user])
|
||||
{
|
||||
if (et2_calendar_view.owner_name_cache[user]) {
|
||||
return et2_calendar_view.owner_name_cache[user];
|
||||
}
|
||||
if (!isNaN(user))
|
||||
{
|
||||
if (!isNaN(user)) {
|
||||
user = parseInt(user);
|
||||
var accounts = egw.accounts('both');
|
||||
for(var j = 0; j < accounts.length; j++)
|
||||
{
|
||||
if(accounts[j].value === user)
|
||||
{
|
||||
for (var j = 0; j < accounts.length; j++) {
|
||||
if (accounts[j].value === user) {
|
||||
label = accounts[j].label;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(typeof label === 'undefined')
|
||||
{
|
||||
if (typeof label === 'undefined') {
|
||||
// Not found? Ask the sidebox owner widget (it gets updated) or the original arrayMgr
|
||||
var options = false
|
||||
if(app.calendar && app.calendar.sidebox_et2 && app.calendar.sidebox_et2.getWidgetById('owner'))
|
||||
{
|
||||
var options = false;
|
||||
if (app.calendar && app.calendar.sidebox_et2 && app.calendar.sidebox_et2.getWidgetById('owner')) {
|
||||
options = app.calendar.sidebox_et2.getWidgetById('owner').taglist.getSelection();
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
options = this.getArrayMgr("sel_options").getRoot().getEntry('owner');
|
||||
}
|
||||
if(options && options.find)
|
||||
{
|
||||
var found = options.find(function(element) {return element.id == user;}) || {};
|
||||
if(found && found.label && found.label !== user)
|
||||
{
|
||||
if (options && options.find) {
|
||||
var found = options.find(function (element) { return element.id == user; }) || {};
|
||||
if (found && found.label && found.label !== user) {
|
||||
label = found.label;
|
||||
}
|
||||
}
|
||||
if(!label)
|
||||
{
|
||||
if (!label) {
|
||||
// No sidebox? Must be in home or sitemgr (no caching) - ask directly
|
||||
label = '?';
|
||||
egw.jsonq('calendar_owner_etemplate_widget::ajax_owner',user,function(data) {
|
||||
egw.jsonq('calendar_owner_etemplate_widget::ajax_owner', user, function (data) {
|
||||
et2_calendar_view.owner_name_cache[user] = data;
|
||||
this.invalidate(true);
|
||||
|
||||
// Set owner to make sure labels get set
|
||||
if(this.owner && typeof this.owner.set_value === 'function')
|
||||
{
|
||||
if (this.owner && typeof this.owner.set_value === 'function') {
|
||||
this.owner.set_value(data);
|
||||
}
|
||||
}.bind(this), this);
|
||||
}
|
||||
}
|
||||
if(label)
|
||||
{
|
||||
if (label) {
|
||||
et2_calendar_view.owner_name_cache[user] = label;
|
||||
}
|
||||
return label;
|
||||
},
|
||||
|
||||
};
|
||||
/**
|
||||
* Find the event information linked to a given DOM node
|
||||
*
|
||||
* @param {HTMLElement} dom_node - It should have something to do with an event
|
||||
* @returns {Object}
|
||||
*/
|
||||
_get_event_info: function _get_event_info(dom_node)
|
||||
{
|
||||
et2_calendar_view.prototype._get_event_info = function (dom_node) {
|
||||
// Determine as much relevant info as can be found
|
||||
var event_node = jQuery(dom_node).closest('[data-id]',this.div)[0];
|
||||
var day_node = jQuery(event_node).closest('[data-date]',this.div)[0];
|
||||
|
||||
var event_node = jQuery(dom_node).closest('[data-id]', this.div)[0];
|
||||
var day_node = jQuery(event_node).closest('[data-date]', this.div)[0];
|
||||
var result = jQuery.extend({
|
||||
event_node: event_node,
|
||||
day_node: day_node
|
||||
},
|
||||
event_node ? event_node.dataset : {},
|
||||
day_node ? day_node.dataset : {}
|
||||
);
|
||||
|
||||
}, event_node ? event_node.dataset : {}, day_node ? day_node.dataset : {});
|
||||
// Widget ID should be the DOM node ID without the event_ prefix
|
||||
if(event_node && event_node.id)
|
||||
{
|
||||
if (event_node && event_node.id) {
|
||||
var widget_id = event_node.id || '';
|
||||
widget_id = widget_id.split('event_');
|
||||
widget_id.shift();
|
||||
result.widget_id = 'event_' + widget_id.join('');
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
};
|
||||
/**
|
||||
* Starting (mousedown) handler to support drag to create
|
||||
*
|
||||
@ -432,176 +367,134 @@ var et2_calendar_view = (function(){ "use strict"; return et2_valueWidget.extend
|
||||
*
|
||||
* @param {String} start Date string (JSON format)
|
||||
*/
|
||||
_drag_create_start: function(start)
|
||||
{
|
||||
this.drag_create.start = jQuery.extend({},start);
|
||||
if(!this.drag_create.start.date)
|
||||
{
|
||||
et2_calendar_view.prototype._drag_create_start = function (start) {
|
||||
this.drag_create.start = jQuery.extend({}, start);
|
||||
if (!this.drag_create.start.date) {
|
||||
this.drag_create.start = null;
|
||||
}
|
||||
this.drag_create.end = start;
|
||||
|
||||
// Clear some stuff, if last time did not complete
|
||||
if(this.drag_create.event)
|
||||
{
|
||||
if(this.drag_create.event.destroy)
|
||||
{
|
||||
if (this.drag_create.event) {
|
||||
if (this.drag_create.event.destroy) {
|
||||
this.drag_create.event.destroy();
|
||||
}
|
||||
this.drag_create.event = null;
|
||||
}
|
||||
// Wait a bit before adding an "event", it may be just a click
|
||||
window.setTimeout(jQuery.proxy(function() {
|
||||
window.setTimeout(jQuery.proxy(function () {
|
||||
// Create event
|
||||
this._drag_create_event();
|
||||
}, this), 250);
|
||||
},
|
||||
|
||||
};
|
||||
/**
|
||||
* Create or update an event used for feedback while dragging on empty space,
|
||||
* so user can see something is happening
|
||||
*/
|
||||
_drag_create_event: function()
|
||||
{
|
||||
if(!this.drag_create.parent || !this.drag_create.start)
|
||||
{
|
||||
et2_calendar_view.prototype._drag_create_event = function () {
|
||||
if (!this.drag_create.parent || !this.drag_create.start) {
|
||||
return;
|
||||
}
|
||||
if(!this.drag_create.event)
|
||||
{
|
||||
this.date_helper.set_value(this.drag_create.start.date);
|
||||
var value = jQuery.extend({},
|
||||
this.drag_create.start,
|
||||
this.drag_create.end,
|
||||
{
|
||||
if (!this.drag_create.event) {
|
||||
this._date_helper.set_value(this.drag_create.start.date);
|
||||
var value = jQuery.extend({}, this.drag_create.start, this.drag_create.end, {
|
||||
start: this.drag_create.start.date,
|
||||
end: this.drag_create.end && this.drag_create.end.date || this.drag_create.start.date,
|
||||
date: ""+this.date_helper.get_year()+
|
||||
sprintf("%02d",this.date_helper.get_month())+
|
||||
sprintf("%02d",this.date_helper.get_date()),
|
||||
date: "" + this._date_helper.get_year() +
|
||||
sprintf("%02d", this._date_helper.get_month()) +
|
||||
sprintf("%02d", this._date_helper.get_date()),
|
||||
title: '',
|
||||
description: '',
|
||||
owner: this.options.owner,
|
||||
participants: this.options.owner,
|
||||
app: 'calendar',
|
||||
whole_day_on_top: this.drag_create.start.whole_day
|
||||
}
|
||||
);
|
||||
this.drag_create.event = et2_createWidget('calendar-event',{
|
||||
id:'event_drag',
|
||||
});
|
||||
this.drag_create.event = et2_createWidget('calendar-event', {
|
||||
id: 'event_drag',
|
||||
value: value
|
||||
},this.drag_create.parent);
|
||||
}, this.drag_create.parent);
|
||||
this.drag_create.event._values_check(value);
|
||||
this.drag_create.event.doLoadingFinished();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
_drag_update_event: function()
|
||||
{
|
||||
if(!this.drag_create.event || !this.drag_create.start || !this.drag_create.end
|
||||
|| !this.drag_create.parent || !this.drag_create.event._type)
|
||||
{
|
||||
};
|
||||
et2_calendar_view.prototype._drag_update_event = function () {
|
||||
if (!this.drag_create.event || !this.drag_create.start || !this.drag_create.end
|
||||
|| !this.drag_create.parent || !this.drag_create.event._type) {
|
||||
return;
|
||||
}
|
||||
else if (this.drag_create.end)
|
||||
{
|
||||
else if (this.drag_create.end) {
|
||||
this.drag_create.event.options.value.end = this.drag_create.end.date;
|
||||
this.drag_create.event._values_check(this.drag_create.event.options.value);
|
||||
}
|
||||
this.drag_create.event._update()
|
||||
this.drag_create.event._update();
|
||||
this.drag_create.parent.position_event(this.drag_create.event);
|
||||
},
|
||||
|
||||
};
|
||||
/**
|
||||
* Ending (mouseup) handler to support drag to create
|
||||
*
|
||||
* @param {String} end Date string (JSON format)
|
||||
*/
|
||||
_drag_create_end: function(end)
|
||||
{
|
||||
this.div.css('cursor','');
|
||||
if(typeof end === 'undefined')
|
||||
{
|
||||
et2_calendar_view.prototype._drag_create_end = function (end) {
|
||||
this.div.css('cursor', '');
|
||||
if (typeof end === 'undefined') {
|
||||
end = {};
|
||||
}
|
||||
|
||||
if(this.drag_create.start && end.date &&
|
||||
JSON.stringify(this.drag_create.start.date) !== JSON.stringify(end.date))
|
||||
{
|
||||
if (this.drag_create.start && end.date &&
|
||||
JSON.stringify(this.drag_create.start.date) !== JSON.stringify(end.date)) {
|
||||
// Drag from start to end, open dialog
|
||||
var options = {
|
||||
start: this.drag_create.start.date < end.date ? this.drag_create.start.date : end.date,
|
||||
end: this.drag_create.start.date < end.date ? end.date : this.drag_create.start.date
|
||||
};
|
||||
|
||||
// Whole day needs to go from 00:00 to 23:59
|
||||
if(end.whole_day || this.drag_create.start.whole_day)
|
||||
{
|
||||
if (end.whole_day || this.drag_create.start.whole_day) {
|
||||
var start = new Date(options.start);
|
||||
start.setUTCHours(0);
|
||||
start.setUTCMinutes(0);
|
||||
options.start = start.toJSON();
|
||||
|
||||
var end = new Date(options.end);
|
||||
end.setUTCHours(23);
|
||||
end.setUTCMinutes(59);
|
||||
options.end = end.toJSON();
|
||||
}
|
||||
|
||||
// Add anything else that was set, but not date
|
||||
jQuery.extend(options,this.drag_create.start, end);
|
||||
delete(options.date);
|
||||
|
||||
jQuery.extend(options, this.drag_create.start, end);
|
||||
delete (options.date);
|
||||
// Make sure parent is set, if needed
|
||||
if (this.drag_create.parent && this.drag_create.parent.options.owner !== app.calendar.state.owner && !options.owner)
|
||||
{
|
||||
if (this.drag_create.parent && this.drag_create.parent.options.owner !== app.calendar.state.owner && !options.owner) {
|
||||
options.owner = this.drag_create.parent.options.owner;
|
||||
}
|
||||
|
||||
// Remove empties
|
||||
for(var key in options)
|
||||
{
|
||||
if(!options[key]) delete options[key];
|
||||
for (var key in options) {
|
||||
if (!options[key])
|
||||
delete options[key];
|
||||
}
|
||||
app.calendar.add(options, this.drag_create.event);
|
||||
|
||||
// Wait a bit, having these stops the click
|
||||
window.setTimeout(jQuery.proxy(function() {
|
||||
window.setTimeout(jQuery.proxy(function () {
|
||||
this.drag_create.start = null;
|
||||
this.drag_create.end = null;
|
||||
this.drag_create.parent = null;
|
||||
if(this.drag_create.event)
|
||||
{
|
||||
if (this.drag_create.event) {
|
||||
this.drag_create.event = null;
|
||||
}
|
||||
},this),100);
|
||||
|
||||
}, this), 100);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.drag_create.start = null;
|
||||
this.drag_create.end = null;
|
||||
this.drag_create.parent = null;
|
||||
if(this.drag_create.event)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(this.drag_create.event.destroy)
|
||||
{
|
||||
if (this.drag_create.event) {
|
||||
try {
|
||||
if (this.drag_create.event.destroy) {
|
||||
this.drag_create.event.destroy();
|
||||
}
|
||||
} catch(e) {}
|
||||
}
|
||||
catch (e) { }
|
||||
this.drag_create.event = null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
});}).call(this);
|
||||
|
||||
// Static class stuff
|
||||
jQuery.extend(et2_calendar_view,
|
||||
{
|
||||
};
|
||||
/**
|
||||
* Check if the view should be consolidated into one, or listed seperately
|
||||
* based on the user's preferences
|
||||
@ -611,22 +504,12 @@ jQuery.extend(et2_calendar_view,
|
||||
* @returns {boolean} True of only one is needed, false if each owner needs
|
||||
* to be listed seperately.
|
||||
*/
|
||||
is_consolidated: function is_consolidated(owners, view)
|
||||
{
|
||||
et2_calendar_view.is_consolidated = function (owners, view) {
|
||||
// Seperate owners, or consolidated?
|
||||
return !(
|
||||
owners.length > 1 &&
|
||||
(view === 'day' && owners.length < parseInt(egw.preference('day_consolidate','calendar')) ||
|
||||
view === 'week' && owners.length < parseInt(egw.preference('week_consolidate','calendar')))
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Cache to map owner & resource IDs to names, helps cut down on server requests
|
||||
*/
|
||||
owner_name_cache: {},
|
||||
|
||||
holiday_cache: {},
|
||||
return !(owners.length > 1 &&
|
||||
(view === 'day' && owners.length < parseInt('' + egw.preference('day_consolidate', 'calendar')) ||
|
||||
view === 'week' && owners.length < parseInt('' + egw.preference('week_consolidate', 'calendar'))));
|
||||
};
|
||||
/**
|
||||
* Fetch and cache a list of the year's holidays
|
||||
*
|
||||
@ -634,47 +517,62 @@ jQuery.extend(et2_calendar_view,
|
||||
* @param {string|numeric} year
|
||||
* @returns {Array}
|
||||
*/
|
||||
get_holidays: function(widget,year)
|
||||
{
|
||||
et2_calendar_view.get_holidays = function (widget, year) {
|
||||
// Loaded in an iframe or something
|
||||
var view = egw.window.et2_calendar_view ? egw.window.et2_calendar_view : this;
|
||||
|
||||
// No country selected causes error, so skip if it's missing
|
||||
if(!view || !egw.preference('country','common')) return {};
|
||||
|
||||
if (!view || !egw.preference('country', 'common'))
|
||||
return {};
|
||||
var cache = view.holiday_cache[year];
|
||||
if (typeof cache == 'undefined')
|
||||
{
|
||||
if (typeof cache == 'undefined') {
|
||||
// Fetch with json instead of jsonq because there may be more than
|
||||
// one widget listening for the response by the time it gets back,
|
||||
// and we can't do that when it's queued.
|
||||
view.holiday_cache[year] = jQuery.getJSON(
|
||||
egw.link('/calendar/holidays.php', {year: year})
|
||||
);
|
||||
view.holiday_cache[year] = jQuery.getJSON(egw.link('/calendar/holidays.php', { year: year }));
|
||||
}
|
||||
cache = view.holiday_cache[year];
|
||||
if(typeof cache.done == 'function')
|
||||
{
|
||||
if (typeof cache.done == 'function') {
|
||||
// pending, wait for it
|
||||
cache.done(jQuery.proxy(function(response) {
|
||||
view.holiday_cache[this.year] = response||undefined;
|
||||
|
||||
egw.window.setTimeout(jQuery.proxy(function() {
|
||||
cache.done(jQuery.proxy(function (response) {
|
||||
view.holiday_cache[this.year] = response || undefined;
|
||||
egw.window.setTimeout(jQuery.proxy(function () {
|
||||
// Make sure widget hasn't been destroyed while we wait
|
||||
if(typeof this.widget.free == 'undefined')
|
||||
{
|
||||
if (typeof this.widget.free == 'undefined') {
|
||||
this.widget.day_class_holiday();
|
||||
}
|
||||
},this),1);
|
||||
},{widget:widget,year:year}))
|
||||
.fail(jQuery.proxy(function() {
|
||||
}, this), 1);
|
||||
}, { widget: widget, year: year }))
|
||||
.fail(jQuery.proxy(function () {
|
||||
view.holiday_cache[this.year] = undefined;
|
||||
}, {widget: widget, year: year}));
|
||||
}, { widget: widget, year: year }));
|
||||
return {};
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
return cache;
|
||||
}
|
||||
};
|
||||
et2_calendar_view._attributes = {
|
||||
owner: {
|
||||
name: "Owner",
|
||||
type: "any",
|
||||
default: [egw.user('account_id')],
|
||||
description: "Account ID number of the calendar owner, if not the current user"
|
||||
},
|
||||
start_date: {
|
||||
name: "Start date",
|
||||
type: "any"
|
||||
},
|
||||
end_date: {
|
||||
name: "End date",
|
||||
type: "any"
|
||||
}
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Cache to map owner & resource IDs to names, helps cut down on server requests
|
||||
*/
|
||||
et2_calendar_view.owner_name_cache = {};
|
||||
et2_calendar_view.holiday_cache = {};
|
||||
return et2_calendar_view;
|
||||
}(et2_core_valueWidget_1.et2_valueWidget));
|
||||
exports.et2_calendar_view = et2_calendar_view;
|
||||
//# sourceMappingURL=et2_widget_view.js.map
|
Loading…
Reference in New Issue
Block a user