forked from CIT/Vmeda.Online
		
	MOBILE-2253 core: Fix boolean inputs in comps and dirs
This commit is contained in:
		
							parent
							
								
									b65b3278fc
								
							
						
					
					
						commit
						6db76d9792
					
				@ -1,2 +1,2 @@
 | 
				
			|||||||
<ng-content></ng-content>
 | 
					<ng-content></ng-content>
 | 
				
			||||||
<ion-icon *ngIf="coreMarkRequired && coreMarkRequired !== 'false'" class="core-input-required-asterisk" name="medical" md="ios-medical" [title]="requiredLabel"></ion-icon> <!-- Use iOS icon because it's more narrow, so it looks better since it's small. -->
 | 
					<ion-icon *ngIf="coreMarkRequired" class="core-input-required-asterisk" name="medical" md="ios-medical" [title]="requiredLabel"></ion-icon> <!-- Use iOS icon because it's more narrow, so it looks better since it's small. -->
 | 
				
			||||||
 | 
				
			|||||||
@ -12,9 +12,10 @@
 | 
				
			|||||||
// See the License for the specific language governing permissions and
 | 
					// See the License for the specific language governing permissions and
 | 
				
			||||||
// limitations under the License.
 | 
					// limitations under the License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { Component, Input, AfterViewInit, ElementRef } from '@angular/core';
 | 
					import { Component, Input, OnInit, AfterViewInit, ElementRef } from '@angular/core';
 | 
				
			||||||
import { TranslateService } from '@ngx-translate/core';
 | 
					import { TranslateService } from '@ngx-translate/core';
 | 
				
			||||||
import { CoreTextUtilsProvider } from '../../providers/utils/text';
 | 
					import { CoreTextUtilsProvider } from '../../providers/utils/text';
 | 
				
			||||||
 | 
					import { CoreUtilsProvider } from '../../providers/utils/utils';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Directive to add a red asterisk for required input fields.
 | 
					 * Directive to add a red asterisk for required input fields.
 | 
				
			||||||
@ -30,16 +31,24 @@ import { CoreTextUtilsProvider } from '../../providers/utils/text';
 | 
				
			|||||||
    selector: '[core-mark-required]',
 | 
					    selector: '[core-mark-required]',
 | 
				
			||||||
    templateUrl: 'mark-required.html'
 | 
					    templateUrl: 'mark-required.html'
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
export class CoreMarkRequiredComponent implements AfterViewInit {
 | 
					export class CoreMarkRequiredComponent implements OnInit, AfterViewInit {
 | 
				
			||||||
    @Input('core-mark-required') coreMarkRequired: boolean|string = true;
 | 
					    @Input('core-mark-required') coreMarkRequired: boolean|string = true;
 | 
				
			||||||
    protected element: HTMLElement;
 | 
					    protected element: HTMLElement;
 | 
				
			||||||
    requiredLabel: string;
 | 
					    requiredLabel: string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(element: ElementRef, private translate: TranslateService, private textUtils: CoreTextUtilsProvider) {
 | 
					    constructor(element: ElementRef, private translate: TranslateService, private textUtils: CoreTextUtilsProvider,
 | 
				
			||||||
 | 
					            private utils: CoreUtilsProvider) {
 | 
				
			||||||
        this.element = element.nativeElement;
 | 
					        this.element = element.nativeElement;
 | 
				
			||||||
        this.requiredLabel = this.translate.instant('mm.core.required');
 | 
					        this.requiredLabel = this.translate.instant('mm.core.required');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Component being initialized.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    ngOnInit() {
 | 
				
			||||||
 | 
					        this.coreMarkRequired = this.utils.isTrueOrOne(this.coreMarkRequired);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Called after the view is initialized.
 | 
					     * Called after the view is initialized.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
 | 
				
			|||||||
@ -13,6 +13,7 @@
 | 
				
			|||||||
// limitations under the License.
 | 
					// limitations under the License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { Component, OnInit, AfterViewInit, Input, ElementRef } from '@angular/core';
 | 
					import { Component, OnInit, AfterViewInit, Input, ElementRef } from '@angular/core';
 | 
				
			||||||
 | 
					import { CoreUtilsProvider } from '../../providers/utils/utils';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Component to allow showing and hiding a password. The affected input MUST have a name to identify it.
 | 
					 * Component to allow showing and hiding a password. The affected input MUST have a name to identify it.
 | 
				
			||||||
@ -44,7 +45,7 @@ export class CoreShowPasswordComponent implements OnInit, AfterViewInit {
 | 
				
			|||||||
    protected input: HTMLInputElement; // Input affected.
 | 
					    protected input: HTMLInputElement; // Input affected.
 | 
				
			||||||
    protected element: HTMLElement; // Current element.
 | 
					    protected element: HTMLElement; // Current element.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(element: ElementRef) {
 | 
					    constructor(element: ElementRef, private utils: CoreUtilsProvider) {
 | 
				
			||||||
        this.element = element.nativeElement;
 | 
					        this.element = element.nativeElement;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -52,7 +53,7 @@ export class CoreShowPasswordComponent implements OnInit, AfterViewInit {
 | 
				
			|||||||
     * Component being initialized.
 | 
					     * Component being initialized.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    ngOnInit() {
 | 
					    ngOnInit() {
 | 
				
			||||||
        this.shown = this.initialShown && this.initialShown !== 'false';
 | 
					        this.shown = this.utils.isTrueOrOne(this.initialShown);
 | 
				
			||||||
        this.selector = 'input[name="' + this.name + '"]';
 | 
					        this.selector = 'input[name="' + this.name + '"]';
 | 
				
			||||||
        this.setData();
 | 
					        this.setData();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -14,6 +14,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import { Directive, Input, AfterViewInit, ElementRef } from '@angular/core';
 | 
					import { Directive, Input, AfterViewInit, ElementRef } from '@angular/core';
 | 
				
			||||||
import { CoreDomUtilsProvider } from '../providers/utils/dom';
 | 
					import { CoreDomUtilsProvider } from '../providers/utils/dom';
 | 
				
			||||||
 | 
					import { CoreUtilsProvider } from '../providers/utils/utils';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Directive to auto focus an element when a view is loaded.
 | 
					 * Directive to auto focus an element when a view is loaded.
 | 
				
			||||||
@ -28,7 +29,7 @@ export class CoreAutoFocusDirective implements AfterViewInit {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected element: HTMLElement;
 | 
					    protected element: HTMLElement;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(element: ElementRef, private domUtils: CoreDomUtilsProvider) {
 | 
					    constructor(element: ElementRef, private domUtils: CoreDomUtilsProvider, private utils: CoreUtilsProvider) {
 | 
				
			||||||
        this.element = element.nativeElement || element;
 | 
					        this.element = element.nativeElement || element;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -36,13 +37,7 @@ export class CoreAutoFocusDirective implements AfterViewInit {
 | 
				
			|||||||
     * Function after the view is initialized.
 | 
					     * Function after the view is initialized.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    ngAfterViewInit() {
 | 
					    ngAfterViewInit() {
 | 
				
			||||||
        let autoFocus;
 | 
					        const autoFocus = this.utils.isTrueOrOne(this.coreAutoFocus);
 | 
				
			||||||
        if (typeof this.coreAutoFocus == 'string') {
 | 
					 | 
				
			||||||
            autoFocus = this.coreAutoFocus && this.coreAutoFocus !== 'false';
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            autoFocus = !!this.coreAutoFocus;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (autoFocus) {
 | 
					        if (autoFocus) {
 | 
				
			||||||
            // If it's a ion-input or ion-textarea, search the right input to use.
 | 
					            // If it's a ion-input or ion-textarea, search the right input to use.
 | 
				
			||||||
            let element = this.element;
 | 
					            let element = this.element;
 | 
				
			||||||
 | 
				
			|||||||
@ -43,15 +43,15 @@ export class CoreFormatTextDirective implements OnInit {
 | 
				
			|||||||
    @Input() siteId?: string; // Site ID to use.
 | 
					    @Input() siteId?: string; // Site ID to use.
 | 
				
			||||||
    @Input() component?: string; // Component for CoreExternalContentDirective.
 | 
					    @Input() component?: string; // Component for CoreExternalContentDirective.
 | 
				
			||||||
    @Input() componentId?: string|number; // Component ID to use in conjunction with the component.
 | 
					    @Input() componentId?: string|number; // Component ID to use in conjunction with the component.
 | 
				
			||||||
    @Input() adaptImg?: boolean = true; // Whether to adapt images to screen width.
 | 
					    @Input() adaptImg?: boolean|string = true; // Whether to adapt images to screen width.
 | 
				
			||||||
    @Input() clean?: boolean; // Whether all the HTML tags should be removed.
 | 
					    @Input() clean?: boolean|string; // Whether all the HTML tags should be removed.
 | 
				
			||||||
    @Input() singleLine?: boolean; // Whether new lines should be removed (all text in single line). Only valid if clean=true.
 | 
					    @Input() singleLine?: boolean|string; // Whether new lines should be removed (all text in single line). Only valid if clean=true.
 | 
				
			||||||
    @Input() maxHeight?: number; // Max height in pixels to render the content box. It should be 50 at least to make sense.
 | 
					    @Input() maxHeight?: number; // Max height in pixels to render the content box. It should be 50 at least to make sense.
 | 
				
			||||||
                                 // Using this parameter will force display: block to calculate height better. If you want to
 | 
					                                 // Using this parameter will force display: block to calculate height better. If you want to
 | 
				
			||||||
                                 // avoid this use class="inline" at the same time to use display: inline-block.
 | 
					                                 // avoid this use class="inline" at the same time to use display: inline-block.
 | 
				
			||||||
    @Input() fullOnClick?: boolean; // Whether it should open a new page with the full contents on click. Only if "max-height"
 | 
					    @Input() fullOnClick?: boolean|string; // Whether it should open a new page with the full contents on click. Only if
 | 
				
			||||||
                                    // is set and the content has been collapsed.
 | 
					                                           // "max-height" is set and the content has been collapsed.
 | 
				
			||||||
    @Input() brOnFull?: boolean; // Whether new lines should be replaced by <br> on full view.
 | 
					    @Input() brOnFull?: boolean|string; // Whether new lines should be replaced by <br> on full view.
 | 
				
			||||||
    @Input() fullTitle?: string; // Title to use in full view. Defaults to "Description".
 | 
					    @Input() fullTitle?: string; // Title to use in full view. Defaults to "Description".
 | 
				
			||||||
    @Output() afterRender?: EventEmitter<any>; // Called when the data is rendered.
 | 
					    @Output() afterRender?: EventEmitter<any>; // Called when the data is rendered.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -225,7 +225,7 @@ export class CoreFormatTextDirective implements OnInit {
 | 
				
			|||||||
            site = siteInstance;
 | 
					            site = siteInstance;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Apply format text function.
 | 
					            // Apply format text function.
 | 
				
			||||||
            return this.textUtils.formatText(this.text, this.clean, this.singleLine);
 | 
					            return this.textUtils.formatText(this.text, this.utils.isTrueOrOne(this.clean), this.utils.isTrueOrOne(this.singleLine));
 | 
				
			||||||
        }).then((formatted) => {
 | 
					        }).then((formatted) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            let div = document.createElement('div'),
 | 
					            let div = document.createElement('div'),
 | 
				
			||||||
@ -264,7 +264,7 @@ export class CoreFormatTextDirective implements OnInit {
 | 
				
			|||||||
                images.forEach((img: HTMLElement) => {
 | 
					                images.forEach((img: HTMLElement) => {
 | 
				
			||||||
                    this.addMediaAdaptClass(img);
 | 
					                    this.addMediaAdaptClass(img);
 | 
				
			||||||
                    this.addExternalContent(img);
 | 
					                    this.addExternalContent(img);
 | 
				
			||||||
                    if (this.adaptImg) {
 | 
					                    if (this.utils.isTrueOrOne(this.adaptImg)) {
 | 
				
			||||||
                        // Create a container for the image and use it instead of the image.
 | 
					                        // Create a container for the image and use it instead of the image.
 | 
				
			||||||
                        let container = this.createMagnifyingGlassContainer(elWidth, img);
 | 
					                        let container = this.createMagnifyingGlassContainer(elWidth, img);
 | 
				
			||||||
                        div.replaceChild(container, img);
 | 
					                        div.replaceChild(container, img);
 | 
				
			||||||
 | 
				
			|||||||
@ -14,6 +14,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import { Directive, AfterViewInit, Input, ElementRef, OnDestroy } from '@angular/core';
 | 
					import { Directive, AfterViewInit, Input, ElementRef, OnDestroy } from '@angular/core';
 | 
				
			||||||
import { CoreDomUtilsProvider } from '../providers/utils/dom';
 | 
					import { CoreDomUtilsProvider } from '../providers/utils/dom';
 | 
				
			||||||
 | 
					import { CoreUtilsProvider } from '../providers/utils/utils';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Directive to keep the keyboard open when clicking a certain element (usually a button).
 | 
					 * Directive to keep the keyboard open when clicking a certain element (usually a button).
 | 
				
			||||||
@ -55,7 +56,7 @@ export class CoreKeepKeyboardDirective implements AfterViewInit, OnDestroy {
 | 
				
			|||||||
    protected focusAgainListener : any; // Another listener for focusout, with the purpose to focus again.
 | 
					    protected focusAgainListener : any; // Another listener for focusout, with the purpose to focus again.
 | 
				
			||||||
    protected stopFocusAgainTimeout: any; // Timeout to stop focus again listener.
 | 
					    protected stopFocusAgainTimeout: any; // Timeout to stop focus again listener.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(element: ElementRef, private domUtils: CoreDomUtilsProvider) {
 | 
					    constructor(element: ElementRef, private domUtils: CoreDomUtilsProvider, private utils: CoreUtilsProvider) {
 | 
				
			||||||
        this.element = element.nativeElement;
 | 
					        this.element = element.nativeElement;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -66,7 +67,7 @@ export class CoreKeepKeyboardDirective implements AfterViewInit, OnDestroy {
 | 
				
			|||||||
        // Use a setTimeout because, if this directive is applied to a button, then the ion-input that it affects
 | 
					        // Use a setTimeout because, if this directive is applied to a button, then the ion-input that it affects
 | 
				
			||||||
        // maybe it hasn't been treated yet.
 | 
					        // maybe it hasn't been treated yet.
 | 
				
			||||||
        setTimeout(() => {
 | 
					        setTimeout(() => {
 | 
				
			||||||
            let inButton = this.inButton && this.inButton !== 'false',
 | 
					            let inButton = this.utils.isTrueOrOne(this.inButton),
 | 
				
			||||||
                candidateEls,
 | 
					                candidateEls,
 | 
				
			||||||
                selectedEl;
 | 
					                selectedEl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -26,8 +26,8 @@ import { CoreConfigConstants } from '../configconstants';
 | 
				
			|||||||
    selector: '[core-link]'
 | 
					    selector: '[core-link]'
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
export class CoreLinkDirective implements OnInit {
 | 
					export class CoreLinkDirective implements OnInit {
 | 
				
			||||||
    @Input() capture?: boolean; // If the link needs to be captured by the app.
 | 
					    @Input() capture?: boolean|string; // If the link needs to be captured by the app.
 | 
				
			||||||
    @Input() inApp?: boolean; // True to open in embedded browser, false to open in system browser.
 | 
					    @Input() inApp?: boolean|string; // True to open in embedded browser, false to open in system browser.
 | 
				
			||||||
    @Input() autoLogin? = 'check'; // If the link should be open with auto-login. Accepts the following values:
 | 
					    @Input() autoLogin? = 'check'; // If the link should be open with auto-login. Accepts the following values:
 | 
				
			||||||
                                   //   "yes" -> Always auto-login.
 | 
					                                   //   "yes" -> Always auto-login.
 | 
				
			||||||
                                   //   "no" -> Never auto-login.
 | 
					                                   //   "no" -> Never auto-login.
 | 
				
			||||||
@ -45,6 +45,8 @@ export class CoreLinkDirective implements OnInit {
 | 
				
			|||||||
     * Function executed when the component is initialized.
 | 
					     * Function executed when the component is initialized.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    ngOnInit() {
 | 
					    ngOnInit() {
 | 
				
			||||||
 | 
					        this.inApp = this.utils.isTrueOrOne(this.inApp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.element.addEventListener('click', (event) => {
 | 
					        this.element.addEventListener('click', (event) => {
 | 
				
			||||||
            // If the event prevented default action, do nothing.
 | 
					            // If the event prevented default action, do nothing.
 | 
				
			||||||
            if (!event.defaultPrevented) {
 | 
					            if (!event.defaultPrevented) {
 | 
				
			||||||
@ -53,7 +55,7 @@ export class CoreLinkDirective implements OnInit {
 | 
				
			|||||||
                    event.preventDefault();
 | 
					                    event.preventDefault();
 | 
				
			||||||
                    event.stopPropagation();
 | 
					                    event.stopPropagation();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (this.capture) {
 | 
					                    if (this.utils.isTrueOrOne(this.capture)) {
 | 
				
			||||||
                        // @todo: Handle link using content links helper.
 | 
					                        // @todo: Handle link using content links helper.
 | 
				
			||||||
                        // $mmContentLinksHelper.handleLink(href).then((treated) => {
 | 
					                        // $mmContentLinksHelper.handleLink(href).then((treated) => {
 | 
				
			||||||
                        //     if (!treated) {
 | 
					                        //     if (!treated) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user