Vmeda.Online/src/components/context-menu/context-menu-popover.ts

70 lines
2.1 KiB
TypeScript
Raw Normal View History

// (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 { Component } from '@angular/core';
import { NavParams, ViewController } from 'ionic-angular';
import { CoreContextMenuItemComponent } from './context-menu-item';
/**
* Component to display a list of items received by param in a popover.
*/
@Component({
selector: 'core-context-menu-popover',
templateUrl: 'context-menu-popover.html'
})
export class CoreContextMenuPopoverComponent {
title: string;
items: CoreContextMenuItemComponent[];
constructor(navParams: NavParams, private viewCtrl: ViewController) {
this.title = navParams.get('title');
this.items = navParams.get('items') || [];
}
/**
* Close the popover.
*/
closeMenu() : void {
this.viewCtrl.dismiss();
}
/**
* Function called when an item is clicked.
*
* @param {Event} event Click event.
* @param {CoreContextMenuItemComponent} item Item clicked.
* @return {boolean} Return true if success, false if error.
*/
itemClicked(event: Event, item: CoreContextMenuItemComponent) : boolean {
if (item.action.observers.length > 0) {
event.preventDefault();
event.stopPropagation();
if (!item.iconAction || item.iconAction == 'spinner') {
return false;
}
if (item.closeOnClick) {
this.closeMenu();
}
item.action.emit(this.closeMenu.bind(this));
} else if (item.href && item.closeOnClick) {
this.closeMenu();
}
return true;
}
}