MOBILE-3087 calendar: Support repeateditall setting

main
Dani Palou 2019-06-27 12:34:08 +02:00
parent 649ad7a1a2
commit 12ce9f63b5
7 changed files with 81 additions and 20 deletions

View File

@ -96,6 +96,7 @@
"addon.calendar.errorloadevents": "local_moodlemobileapp",
"addon.calendar.eventduration": "calendar",
"addon.calendar.eventendtime": "calendar",
"addon.calendar.eventkind": "calendar",
"addon.calendar.eventname": "calendar",
"addon.calendar.eventstarttime": "calendar",
"addon.calendar.eventtype": "calendar",
@ -106,6 +107,9 @@
"addon.calendar.noevents": "local_moodlemobileapp",
"addon.calendar.nopermissiontoupdatecalendar": "error",
"addon.calendar.reminders": "local_moodlemobileapp",
"addon.calendar.repeatedevents": "calendar",
"addon.calendar.repeateditall": "calendar",
"addon.calendar.repeateditthis": "calendar",
"addon.calendar.repeatevent": "calendar",
"addon.calendar.repeatweeksl": "calendar",
"addon.calendar.setnewreminder": "local_moodlemobileapp",

View File

@ -12,6 +12,7 @@
"errorloadevents": "Error loading events.",
"eventduration": "Duration",
"eventendtime": "End time",
"eventkind": "Type of event",
"eventname": "Event title",
"eventstarttime": "Start time",
"eventtype": "Event type",
@ -22,6 +23,9 @@
"noevents": "There are no events",
"nopermissiontoupdatecalendar": "Sorry, but you do not have permission to update the calendar event",
"reminders": "Reminders",
"repeatedevents": "Repeated events",
"repeateditall": "Also apply changes to the other {{$a}} events in this repeat series",
"repeateditthis": "Apply changes to this event only",
"repeatevent": "Repeat this event",
"repeatweeksl": "Repeat weekly, creating altogether",
"setnewreminder": "Set a new reminder",

View File

@ -26,7 +26,7 @@
<!-- Type. -->
<ion-item text-wrap class="addon-calendar-eventtype-container">
<ion-label id="addon-calendar-eventtype-label"><h2 [core-mark-required]="true">{{ 'addon.calendar.eventtype' | translate }}</h2></ion-label>
<ion-label id="addon-calendar-eventtype-label"><h2 [core-mark-required]="true">{{ 'addon.calendar.eventkind' | translate }}</h2></ion-label>
<ion-select [formControlName]="'eventtype'" aria-labelledby="addon-calendar-eventtype-label" interface="action-sheet" [disabled]="eventTypes.length == 1">
<ion-option *ngFor="let type of eventTypes" [value]="type.value">{{ type.name | translate }}</ion-option>
</ion-select>
@ -96,8 +96,8 @@
</ion-item>
<!-- Duration. -->
<div text-wrap radio-group [formControlName]="'duration'" class="addon-calendar-duration-container">
<ion-item class="addon-calendar-duration-title"><h2>{{ 'addon.calendar.eventduration' | translate }}</h2></ion-item>
<div text-wrap radio-group [formControlName]="'duration'" class="addon-calendar-radio-container">
<ion-item class="addon-calendar-radio-title"><h2>{{ 'addon.calendar.eventduration' | translate }}</h2></ion-item>
<ion-item>
<ion-label>{{ 'addon.calendar.durationnone' | translate }}</ion-label>
<ion-radio [value]="0"></ion-radio>
@ -118,15 +118,30 @@
</ion-item>
</div>
<!-- Repeat. -->
<ion-item text-wrap>
<ion-label><h2>{{ 'addon.calendar.repeatevent' | translate }}</h2></ion-label>
<ion-checkbox item-end [formControlName]="'repeat'"></ion-checkbox>
</ion-item>
<ion-item text-wrap *ngIf="eventForm.controls.repeat.value">
<ion-label stacked><h2>{{ 'addon.calendar.repeatweeksl' | translate }}</h2></ion-label>
<ion-input type="number" name="repeats" [formControlName]="'repeats'"></ion-input>
</ion-item>
<!-- Repeat (for new events). -->
<ng-container *ngIf="!eventId || eventId < 0">
<ion-item text-wrap>
<ion-label><h2>{{ 'addon.calendar.repeatevent' | translate }}</h2></ion-label>
<ion-checkbox item-end [formControlName]="'repeat'"></ion-checkbox>
</ion-item>
<ion-item text-wrap *ngIf="eventForm.controls.repeat.value">
<ion-label stacked><h2>{{ 'addon.calendar.repeatweeksl' | translate }}</h2></ion-label>
<ion-input type="number" name="repeats" [formControlName]="'repeats'"></ion-input>
</ion-item>
</ng-container>
<!-- Apply to all events or just this one (editing repeated events). -->
<div *ngIf="event && event.repeatid" text-wrap radio-group [formControlName]="'repeateditall'" class="addon-calendar-radio-container">
<ion-item class="addon-calendar-radio-title"><h2>{{ 'addon.calendar.repeatedevents' | translate }}</h2></ion-item>
<ion-item>
<ion-label>{{ 'addon.calendar.repeateditall' | translate:{$a: event.othereventscount} }}</ion-label>
<ion-radio [value]="1"></ion-radio>
</ion-item>
<ion-item>
<ion-label>{{ 'addon.calendar.repeateditthis' | translate }}</ion-label>
<ion-radio [value]="0"></ion-radio>
</ion-item>
</div>
</ng-container>
<ion-item>

View File

@ -1,5 +1,5 @@
ion-app.app-root page-addon-calendar-edit-event {
.addon-calendar-duration-container ion-item:not(.addon-calendar-duration-title) {
.addon-calendar-radio-container ion-item:not(.addon-calendar-radio-title) {
&.item-ios {
@include padding-horizontal($item-ios-padding-start * 2, null);

View File

@ -57,6 +57,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
courseGroupSet = false;
advanced = false;
errors: any;
event: any; // The event object (when editing an event).
// Form variables.
eventForm: FormGroup;
@ -72,6 +73,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
protected showAll: boolean;
protected isDestroyed = false;
protected error = false;
protected gotEventData = false;
constructor(navParams: NavParams,
private navCtrl: NavController,
@ -126,6 +128,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
this.eventForm.addControl('timedurationminutes', this.fb.control(''));
this.eventForm.addControl('repeat', this.fb.control(false));
this.eventForm.addControl('repeats', this.fb.control('1'));
this.eventForm.addControl('repeateditall', this.fb.control(1));
}
/**
@ -164,7 +167,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
return Promise.reject(this.translate.instant('addon.calendar.nopermissiontoupdatecalendar'));
}
if (this.eventId && !refresh) {
if (this.eventId && !this.gotEventData) {
// Editing an event, get the event data. Wait for sync first.
promises.push(this.calendarSync.waitForSync(AddonCalendarSyncProvider.SYNC_ID).then(() => {
@ -173,20 +176,35 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
this.syncProvider.blockOperation(AddonCalendarProvider.COMPONENT, this.eventId);
}
const promises = [];
// Get the event offline data if there's any.
return this.calendarOffline.getEvent(this.eventId).then((event) => {
promises.push(this.calendarOffline.getEvent(this.eventId).then((event) => {
this.hasOffline = true;
return event;
}).catch(() => {
// No offline data.
this.hasOffline = false;
}));
if (this.eventId > 0) {
// It's an online event. get its data from server.
promises.push(this.calendarProvider.getEventById(this.eventId).then((event) => {
this.event = event;
if (event && event.repeatid) {
event.othereventscount = event.eventcount ? event.eventcount - 1 : '';
}
return event;
}));
}
return Promise.all(promises).then((result) => {
this.gotEventData = true;
const event = result[0] || result[1]; // Use offline data first.
if (this.eventId > 0) {
// It's an online event. get its data from server.
return this.calendarProvider.getEventById(this.eventId);
}
}).then((event) => {
if (event) {
// Load the data in the form.
this.eventForm.controls.name.setValue(event.name);
@ -204,6 +222,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
this.eventForm.controls.timedurationminutes.setValue(event.timedurationminutes || '');
this.eventForm.controls.repeat.setValue(!!event.repeat);
this.eventForm.controls.repeats.setValue(event.repeats || '1');
this.eventForm.controls.repeateditall.setValue(event.repeateditall || 1);
}
});
}));
@ -394,6 +413,11 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
data.repeats = formData.repeats;
}
if (this.event && this.event.repeatid) {
data.repeatid = this.event.repeatid;
data.repeateditall = formData.repeateditall;
}
// Send the data.
const modal = this.domUtils.showModalLoading('core.sending', true);

View File

@ -94,6 +94,14 @@ export class AddonCalendarOfflineProvider {
name: 'repeats',
type: 'TEXT',
},
{
name: 'repeatid',
type: 'INTEGER',
},
{
name: 'repeateditall',
type: 'INTEGER',
},
{
name: 'userid',
type: 'INTEGER',
@ -202,6 +210,8 @@ export class AddonCalendarOfflineProvider {
timedurationminutes: data.timedurationminutes,
repeat: data.repeat ? 1 : 0,
repeats: data.repeats,
repeatid: data.repeatid,
repeateditall: data.repeateditall ? 1 : 0,
timecreated: timeCreated,
userid: site.getUserId()
};

View File

@ -96,6 +96,7 @@
"addon.calendar.errorloadevents": "Error loading events.",
"addon.calendar.eventduration": "Duration",
"addon.calendar.eventendtime": "End time",
"addon.calendar.eventkind": "Type of event",
"addon.calendar.eventname": "Event title",
"addon.calendar.eventstarttime": "Start time",
"addon.calendar.eventtype": "Event type",
@ -106,6 +107,9 @@
"addon.calendar.noevents": "There are no events",
"addon.calendar.nopermissiontoupdatecalendar": "Sorry, but you do not have permission to update the calendar event",
"addon.calendar.reminders": "Reminders",
"addon.calendar.repeatedevents": "Repeated events",
"addon.calendar.repeateditall": "Also apply changes to the other {{$a}} events in this repeat series",
"addon.calendar.repeateditthis": "Apply changes to this event only",
"addon.calendar.repeatevent": "Repeat this event",
"addon.calendar.repeatweeksl": "Repeat weekly, creating altogether",
"addon.calendar.setnewreminder": "Set a new reminder",