forked from CIT/Vmeda.Online
		
	
		
			
				
	
	
		
			83 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			83 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
 | 
						||
// (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';
 | 
						||
import { CoreUserProfileFieldHandler, CoreUserProfileFieldHandlerData } from '../../../../core/user/providers/user-profile-field-delegate';
 | 
						||
import { AddonUserProfileFieldTextareaComponent } from '../component/textarea';
 | 
						||
import { CoreTextUtilsProvider } from '../../../../providers/utils/text';
 | 
						||
import { CoreDomUtilsProvider } from '../../../../providers/utils/dom';
 | 
						||
 | 
						||
/**
 | 
						||
 * Textarea user profile field handlers.
 | 
						||
 */
 | 
						||
@Injectable()
 | 
						||
export class AddonUserProfileFieldTextareaHandler implements CoreUserProfileFieldHandler {
 | 
						||
    name = 'textarea';
 | 
						||
 | 
						||
    constructor(private textUtils: CoreTextUtilsProvider, private domUtils: CoreDomUtilsProvider) {}
 | 
						||
 | 
						||
    /**
 | 
						||
     * Whether or not the handler is enabled on a site level.
 | 
						||
     *
 | 
						||
     * @return {boolean|Promise<boolean>} True or promise resolved with true if enabled.
 | 
						||
     */
 | 
						||
    isEnabled() : boolean|Promise<boolean> {
 | 
						||
        return true;
 | 
						||
    }
 | 
						||
 | 
						||
    /**
 | 
						||
     * Get the data to send for the field based on the input data.
 | 
						||
     *
 | 
						||
     * @param  {any}     field          User field to get the data for.
 | 
						||
     * @param  {boolean} signup         True if user is in signup page.
 | 
						||
     * @param  {string}  [registerAuth] Register auth method. E.g. 'email'.
 | 
						||
     * @param  {any}     model          Model with the input data.
 | 
						||
     * @return {Promise<CoreUserProfileFieldHandlerData>}  Data to send for the field.
 | 
						||
     */
 | 
						||
    getData(field: any, signup: boolean, registerAuth: string, model: any): Promise<CoreUserProfileFieldHandlerData> {
 | 
						||
        let name = 'profile_field_' + field.shortname;
 | 
						||
 | 
						||
        if (model[name]) {
 | 
						||
            return this.domUtils.isRichTextEditorEnabled().then((enabled) => {
 | 
						||
                let text = model[name].text || '';
 | 
						||
                if (!enabled) {
 | 
						||
                    // Rich text editor not enabled, add some HTML to the message if needed.
 | 
						||
                    text = this.textUtils.formatHtmlLines(text);
 | 
						||
                }
 | 
						||
 | 
						||
                return {
 | 
						||
                    type: 'textarea',
 | 
						||
                    name: name,
 | 
						||
                    value: JSON.stringify({
 | 
						||
                        text: text,
 | 
						||
                        format: model[name].format || 1
 | 
						||
                    })
 | 
						||
                };
 | 
						||
            });
 | 
						||
        }
 | 
						||
    }
 | 
						||
 | 
						||
    /**
 | 
						||
     * Return the Component to use to display the user profile field.
 | 
						||
     *
 | 
						||
     * @param  {any}     field          User field to get the data for.
 | 
						||
     * @param  {boolean} signup         True if user is in signup page.
 | 
						||
     * @param  {string}  [registerAuth] Register auth method. E.g. 'email'.
 | 
						||
     * @return {any}     The component to use, undefined if not found.
 | 
						||
     */
 | 
						||
    getComponent(field: any, signup: boolean, registerAuth: string) {
 | 
						||
        return AddonUserProfileFieldTextareaComponent;
 | 
						||
    }
 | 
						||
 | 
						||
} |