2018-01-15 15:57:42 +01:00
|
|
|
// (C) Copyright 2015 Martin Dougiamas
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
import { Injectable } from '@angular/core';
|
2018-01-16 15:52:07 +01:00
|
|
|
import { CoreUserDelegate, CoreUserProfileHandler, CoreUserProfileHandlerData } from './user-delegate';
|
2018-03-01 16:55:49 +01:00
|
|
|
import { CoreSitesProvider } from '@providers/sites';
|
2018-01-15 15:57:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Profile links email handler.
|
|
|
|
*/
|
|
|
|
@Injectable()
|
|
|
|
export class CoreUserProfileMailHandler implements CoreUserProfileHandler {
|
|
|
|
name = 'mmUser';
|
|
|
|
priority = 700;
|
|
|
|
type = CoreUserDelegate.TYPE_COMMUNICATION;
|
|
|
|
|
2018-01-29 10:05:20 +01:00
|
|
|
constructor(protected sitesProvider: CoreSitesProvider) { }
|
2018-01-15 15:57:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if handler is enabled.
|
|
|
|
*
|
|
|
|
* @return {boolean} Always enabled.
|
|
|
|
*/
|
|
|
|
isEnabled(): boolean {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if handler is enabled for this user in this context.
|
|
|
|
*
|
|
|
|
* @param {any} user User to check.
|
|
|
|
* @param {number} courseId Course ID.
|
2018-02-14 12:46:40 +01:00
|
|
|
* @param {any} [navOptions] Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
|
|
|
|
* @param {any} [admOptions] Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
|
2018-01-15 15:57:42 +01:00
|
|
|
* @return {boolean|Promise<boolean>} Promise resolved with true if enabled, resolved with false otherwise.
|
|
|
|
*/
|
2018-01-29 10:05:20 +01:00
|
|
|
isEnabledForUser(user: any, courseId: number, navOptions?: any, admOptions?: any): boolean | Promise<boolean> {
|
2018-01-15 15:57:42 +01:00
|
|
|
// Not current user required.
|
|
|
|
return user.id != this.sitesProvider.getCurrentSite().getUserId() && user.email;
|
2018-01-29 10:05:20 +01:00
|
|
|
}
|
2018-01-15 15:57:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the data needed to render the handler.
|
|
|
|
*
|
|
|
|
* @return {CoreUserProfileHandlerData} Data needed to render the handler.
|
|
|
|
*/
|
|
|
|
getDisplayData(user: any, courseId: number): CoreUserProfileHandlerData {
|
|
|
|
return {
|
|
|
|
icon: 'mail',
|
|
|
|
title: 'core.user.sendemail',
|
|
|
|
class: 'core-user-profile-mail',
|
2018-01-30 14:43:05 +01:00
|
|
|
action: (event, navCtrl, user, courseId): void => {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2018-01-29 10:05:20 +01:00
|
|
|
window.open('mailto:' + user.email, '_blank');
|
2018-01-15 15:57:42 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|