20
20
import Ubuntu.Components 1.1
21
21
import QtOrganizer 5.0
22
22
import "Defines.js" as Defines
23
import "Recurrence.js" as Recurrence
27
29
function getWeekDaysIndex(daysOfWeek){
29
if(compareArrays(daysOfWeek,[Qt.Monday,Qt.Tuesday,Qt.Wednesday,Qt.Thursday,Qt.Friday]))
31
else if(compareArrays(daysOfWeek,[Qt.Monday,Qt.Wednesday,Qt.Friday]))
33
else if(compareArrays(daysOfWeek,[Qt.Tuesday,Qt.Thursday]))
30
for (var index = Recurrence.Weekdays; index < Recurrence.OnDiffDays; index++) {
31
if (compareArrays(daysOfWeek, Recurrence.weeklyDays[index])) {
35
return Recurrence.OnDiffDays;
40
function compareArrays(daysOfWeek, actualArray){
38
function compareArrays(daysOfWeek, actualArray) {
41
39
if (daysOfWeek.length !== actualArray.length) return false;
42
40
for (var i = 0; i < actualArray.length; i++) {
43
41
if (daysOfWeek[i] !== actualArray[i]) return false;
47
function getDaysOfWeek(index,weekDays){
46
function getDaysOfWeek(index, weekDays) {
48
47
var daysOfWeek = [];
51
daysOfWeek = [Qt.Monday,Qt.Tuesday,Qt.Wednesday,Qt.Thursday,Qt.Friday];
54
daysOfWeek = [Qt.Monday,Qt.Wednesday,Qt.Friday];
57
daysOfWeek = [Qt.Tuesday,Qt.Thursday];
48
if (index !== Recurrence.OnDiffDays) {
49
daysOfWeek = Recurrence.weeklyDays[index];
60
51
daysOfWeek = weekDays.length === 0 ? [date.getDay()] : weekDays;
65
56
//Function to get Weeknames in narrow Format
66
57
function getDays(daysOfWeek) {
68
for(var j = 0;j<daysOfWeek.length;++j){
59
for (var j = 0; j < daysOfWeek.length; ++j) {
70
days.push(Qt.locale().dayName(daysOfWeek[j],Locale.NarrowFormat))
61
days.push(Qt.locale().dayName(daysOfWeek[j], Locale.NarrowFormat))
72
63
days = days.join(', ');
76
function getRecurrenceString(rule){
67
function getString(rule,recurrence){
81
68
var dateFormat = Qt.locale().dateFormat(Locale.LongFormat);
82
index = rule.frequency;
83
if(index === RecurrenceRule.Weekly){
84
index = getWeekDaysIndex(rule.daysOfWeek.sort() )
85
reccurence = "Weekly "
87
reccurence += "on " + getDays(rule.daysOfWeek.sort())
70
if (rule.limit === undefined) {
71
str = i18n.tr(recurrence)
72
} else if (rule.limit !== undefined && parseInt(rule.limit)) {
73
// TRANSLATORS: the argument refers to multiple recurrence of event with count .
74
// E.g. "Daily; 5 times."
75
str = i18n.tr("%1; %2 time", "%1; %2 times", rule.limit).arg(recurrence).arg(rule.limit)
77
// TRANSLATORS: the argument refers to recurrence until user selected date.
78
// E.g. "Daily; until 12/12/2014."
79
str = i18n.tr("%1; until %2").arg(recurrence).arg(rule.limit.toLocaleString(Qt.locale(), dateFormat))
90
else if(index === RecurrenceRule.Monthly)
92
else if(index === RecurrenceRule.Yearly)
95
reccurence += Defines.recurrenceLabel[index]
97
str = (rule.limit === undefined) ? i18n.tr(reccurence) :
98
(rule.limit !== undefined && parseInt(rule.limit)) ?
99
i18n.tr("%1 ; %2 times ").arg(reccurence).arg(rule.limit) :
100
i18n.tr("%1 ; until %2").arg(reccurence).arg(rule.limit.toLocaleString(Qt.locale(), dateFormat))
84
function getRecurrenceString(rule) {
85
var index = rule.frequency;
88
//Check if reccurence is weekly or not
89
if (index === RecurrenceRule.Weekly) {
90
index = getWeekDaysIndex(rule.daysOfWeek.sort())
91
// We are using a custom index
92
// because we have more options than the Qt RecurrenceRule enum.
93
} else if (index === RecurrenceRule.Monthly) {
94
index = Recurrence.Monthly // If reccurence is Monthly
95
} else if (index === RecurrenceRule.Yearly) {
96
index = Recurrence.Yearly // If reccurence is Yearly
98
// if reccurrence is on different days.
99
if (index === Recurrence.OnDiffDays) {
100
// TRANSLATORS: the argument refers to several different days of the week.
101
// E.g. "Weekly on Mondays, Tuesdays"
102
recurrence += i18n.tr("Weekly on %1").arg(getDays(rule.daysOfWeek.sort()))
104
recurrence += Defines.recurrenceLabel[index]
106
str = getString(rule,recurrence);