Syncfusion Open URL in Menu Item in a new Tab - syncfusion

I have a Menu in Syncfusion Angular. The Menu Item should navigate to an URL in new tab. It is opening in same tab by overriding the website. How to acheive this.
#ViewChild('sidebarMenuInstance')
public sidebarMenuInstance: SidebarComponent;
#ViewChild('menu')
private menuObj: MenuComponent;
public menuItems: MenuItemModel[] = [
{
text: 'Menu Item',
iconCss: 'icon',
items: [
{
text: 'Link', iconCss: 'icon-picture icon', url: 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
}
],
}
];

private beforeItemRender(args: MenuEventArgs): void {
if (args.item.url) {
// To open url in blank page.
args.element.getElementsByTagName('a')[0].setAttribute('target', '_blank');
}

Related

Title and menu items of sap.ui.unified.Menu control

I am trying to add title to a sap.ui.unified.Menu control and it displays only the title; other menu items after this are not displayed.
How to bind the menu items to this, and how to get same view with other data without new menu element being created?
I want this :
I am getting :
My code:
sap.ui.define([], function () {
var dynamicMenu= new sap.ui.unified.Menu.extend("com.google.copa.common.CustomMenu", {
metadata: {
library: "com.google.copa.common",
properties: {
title: {
type: "string" } } },
init : function () { },
renderer:function(oRm,oControl){
oRm.write("<div");
oRm.writeControlData(oControl);
oRm.addClass("myCustTitle");
oRm.writeClasses();
oRm.write(">");
oRm.write("<h2>"+oControl.getTitle()+"</h2>");
oRm.write("</div>");
oRm.write(oControl); },
setTitle:function(val){
this.setProperty("title",val,true);
return this; } });
return dynamicMenu; })
This is how I am calling my custom Control:
var menu=new CustomMenu({ title:"MyCustom Title" });
var oItemTemplate = new sap.ui.unified.MenuItem({
text: "{description}",press:e=>alert("test") });
menu.bindAggregation("items", {
path: "/plants",
template: oItemTemplate });
thisOfBtn.getView().addDependent(menu);
menu.setModel(that.getModel());
// const eDock = sap.ui.core.Popup.Dock;
// unable to align position of popup
// menu.openBy(oButton.getFocusDomRef(),true, "EndTop", "EndBottom","0 -2");
menu.open(true,oButton.getFocusDomRef(),"BeginTop", "BeginBottom", oButton.getParent().getDomRef());
Try calling oRm.renderControl(oControl) instead of oRm.write(oControl)

Tabs Disappearing After Navigating Away (Side Menu + Tabs)

I have an app that uses a side menu and tabs based off the Ionic Conference App. The app works as expected at the start and the tabs and side menu are both shown but when you go to a non-tabs page and then back to a tabs page via the side menu the tabs disappear. Here’s my relevant code. Any one have any ideas why this may not be working as expected? :x
export class MyApp {
// Reference to the app's root nav
#ViewChild(Nav) nav: Nav;
rootPage: any;
pages: PageInterface[] = [
{ title: 'Applications', pageName: 'HomePage', index: 0, icon: 'home' },
{ title: 'New Entries ', pageName: 'JobEntryPage', index: 1, icon: 'map' },
{ title: 'Statistics', pageName: 'StatisticsPage', index: 2, icon: 'stats'},
];
socialPages: PageInterface[] = [
{ title: 'Company List', pageName: 'CompaniesPage', component:
'CompaniesPage', icon: 'log-out'}
];
accountPages: PageInterface[] = [
{ title: 'Profile', pageName: 'ProfilePage', component: 'ProfilePage', icon:
'person' },
{ title: 'Logout', pageName: 'LogoutPage', component: 'LogoutPage', icon:
'log-out'}
];
constructor(public platform: Platform, public statusBar: StatusBar, public
splashScreen: SplashScreen,
private afAuth: AngularFireAuth, public fb: FirebaseProvider,
public menu: MenuController) {
this.initializeApp();
this.afAuth.authState.subscribe(auth => {
if(!auth)
this.rootPage = 'LoginPage';
else
this.rootPage = 'TabsPage';
});
}
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
openPage(page: PageInterface) {
let params = {};
// the nav component was found using #ViewChild(Nav)
// setRoot on the nav to remove previous pages and only have this page
// we wouldn't want the back button to show in this scenario
if (page.index) {
params = { tabIndex: page.index };
}
// If we are already on tabs just change the selected tab
// don't setRoot again, this maintains the history stack of the
// tabs even if changing them from the menu
if (this.nav.getActiveChildNavs().length && page.index != undefined) {
this.nav.getActiveChildNavs()[0].select(page.index);
// Set the root of the nav with params if it's a tab index
} else {
console.log(page.pageName)
this.nav.setRoot(page.pageName, params).catch((err: any) => {
console.log(`Didn't set nav root: ${err}`);
});
}
}

Ionic2 alert with dropdown?

I am building an Ionic2 app. I have an alert like following:
constructor(private platform: Platform, public nav : NavController,
public exhibitionSurveyObjectService : ExhibitionSurveyObjectService ) {
this.initializeMap();
this.nav=nav;
this.testArray=[];
this.area=null;
}
addSurveyObject(){
let prompt = Alert.create({
title: 'Subscribe to our service',
message: "All the fields are necessary",
inputs: [
{
name: 'name',
placeholder: 'Name'
},
....
{
name: 'cycle',
placeholder: 'Cycle: once/weekly/monthly'
},
{
name: 'object_type',
placeholder: 'Farm/Solarpanel/plain'
},
],
buttons: [
....
{
text: 'Save',
handler: data => {
this.createExhibitionSuveyObject(data);
}
}
]
});
this.nav.present(prompt);
}
createExhibitionSuveyObject(data: any){
var cycle = data.cycle;
cycle = cycle.toUpperCase()
console.log(cycle)
var type = data.object_type;
type = type.toUpperCase()
console.log(type)
this.exhibitionSurveyObjectService.addObject(
data.name, data.farmer_email,
data.farmer_name, data.size, data.path, cycle, type).subscribe(
response => {
this.exhibitionSurveyObjects = response;
this.sayThanks();
},
error => {
this.errorMessage = <any>error;
console.log("error")
}
);
}
sayThanks(){
let alert = Alert.create({
title: 'Thank you!',
subTitle: 'We have received your data, we will get back to you soon!',
buttons: [{
text: 'Ok',
handler: () => {
this.nav.push(HomePage)
}
}]
});
this.nav.present(alert);
}
I want the last two fields to be dropdowns. How can I achieve this?
UPDATE: updated the code snippet with some more code. How it can be updated to use Modal instead of alert?
Just like you can see in Ionic2 docs
Alerts can also include several different inputs whose data can be
passed back to the app. Inputs can be used as a simple way to prompt
users for information. Radios, checkboxes and text inputs are all
accepted, but they cannot be mixed. For example, an alert could have
all radio button inputs, or all checkbox inputs, but the same alert
cannot mix radio and checkbox inputs.
And...
If you require a complex form UI which doesn't fit within the
guidelines of an alert then we recommend building the form within a
modal instead.
So you'll have to create a new Component with that form and then use it to create the Modal:
import { Modal, NavController, NavParams } from 'ionic-angular';
#Component(...)
class YourPage {
constructor(nav: NavController) {
this.nav = nav;
}
presentSubscriptionModal() {
let subscriptionModal = Modal.create(Subscription, { yourParam: paramValue });
this.nav.present(subscriptionModal);
}
}
#Component(...)
class Subscription{
constructor(params: NavParams) {
let param = params.get('yourParam');
}
}

is it possible to change button's text with $ionicPopup.confirm()?

I'm using $ionicPopup.confirm() but I would like to change "cancel's button" text. Is it possible to do so ?
I'm aware of .show() syntax:
buttons: [
{ text: 'Cancel' }
]
But it does not seem to work with .confirm() ...
Thank 4 the help
At least in the latest release of Ionic (1.0.0) you can do the following:
var confirmPopup = $ionicPopup.confirm({
title: 'Popup title',
template: 'Popup text',
cancelText: 'Custom cancel',
okText: 'Custom ok'
}).then(function(res) {
if (res) {
console.log('confirmed');
}
});
Here is the relative documentation.
UPDATE : on ionic 1.0.0, this is now possible, check here
showConfirm Options :
{
title: '', // String. The title of the popup.
cssClass: '', // String, The custom CSS class name
subTitle: '', // String (optional). The sub-title of the popup.
template: '', // String (optional). The html template to place in the popup body.
templateUrl: '', // String (optional). The URL of an html template to place in the popup body.
cancelText: '', // String (default: 'Cancel'). The text of the Cancel button.
cancelType: '', // String (default: 'button-default'). The type of the Cancel button.
okText: '', // String (default: 'OK'). The text of the OK button.
okType: '', // String (default: 'button-positive'). The type of the OK button.
}
Yes you can do wathever you want, using ionic popup.show and bind the Cancel event.
$ionicPopup.show({
template: msg,
title: titleConfirm,
buttons: [
{ text: "BTN_NO",
onTap:function(e){
return false;
}
},
{ text: "BTN_OK",
onTap:function(e){
return true;
}
},
]
});
After investigation on the ionic popover.confirm function this is
not possible to customize it. The value of popover.confirm are hardcoded line 446
function showConfirm(opts) {
return showPopup(extend({
buttons: [{
text: opts.cancelText || 'Cancel',
type: opts.cancelType || 'button-default',
onTap: function() { return false; }
}, {
text: opts.okText || 'OK',
type: opts.okType || 'button-positive',
onTap: function() { return true; }
}]
}, opts || {}));
}
It's possible to do, you have to use the "type" thing inside the button
buttons: [
{ text: 'Cancel' },
{
text: '<b>Save</b>',
type: 'button-assertive',
onTap: function(e) {
$scope.request_form.abc = "accepted";
}
}
]
in the type part you have to give the class name , and you can change the color of the button.

BlackBerry10 cascades :cannot access control objects from QML in c++

In my project, I have two qml files viz. main.qml and DetailsPage.qml.
I am trying to change the text of a label of DetailsPage.qml from c++ using findChild() method.
This is the code in c++ file and DetailsPage.qml
Myfile.cpp code:
using namespace bb::cascades;
AbstractPane *root;
AbstractPane *root1;
Navigater::Navigater
(bb::cascades::Application *app):QObject(app)
{
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
QmlDocument *qml1 = QmlDocument::create("asset:///DetailsPage.qml").parent(this);
qml->setContextProperty("_app", this);
qml1->setContextProperty("_app", this);
root = qml->createRootObject<AbstractPane>();
root1 = qml1->createRootObject<AbstractPane>();
app->setScene(root);
}
void Navigater::tr1()
{
Label *tryLabel1 = root1->findChild<Label*>("labelObj");
if(tryLabel1)
{
qDebug()<<"tttt "<<tryLabel1->text(); //initial text
tryLabel1->setText("Hello!!!!!!!") ;
qDebug()<<"yyyy "<<tryLabel1->text(); //changedText gets reflected on DeviceLog but not on UI
}
else
{
qDebug()<<"Not Found";}
}
DetailsPage.qml code:
// Navigation pane project template
import
bb.cascades 1.0
Page
{
// page with a picture detail
id: pgDetail
actions: [
ActionItem {
title: qsTr("Break")
onTriggered: {
_app.tr1();
imgView.imageSource = "asset: //images/picture1br.png"
}
}
]
paneProperties: NavigationPaneProperties {
backButton: ActionItem {
onTriggered: {
navigationPane.pop()
}
}
}
onCreationCompleted: {
_app.tr1();
}
Container {
background: Color.Black
Label {
objectName: "labelObj" // control to be found
text: "Page 2"
horizontalAlignment: HorizontalAlignment.Center
textStyle {
base: SystemDefaults.TextStyles.TitleText
color: Color.Yellow
}
}
ImageView {
id: imgView
imageSource: "asset:///images/picture1.png"
horizontalAlignment: HorizontalAlignment.Center
}
Label {
text: qsTr("Picture description")
horizontalAlignment: HorizontalAlignment.Center
}
}
}
Change I have made is not getting reflected in simulator...but visible on device log.
Is there any way to access control objects from multiple pages i.e pages other than main.qml?
Could you please look into it.
You can use a navigation pane, add main.qml as page contents and details page as attachedObjects in the navigation pane like
attachedObjects: [
ComponentDefinition {
id: secondPageDefinition
source: "DetailsPage.qml"
}
in main page action add
onClicked: {
// show detail page when the button is clicked
var page = secondPageDefinition.createObject();
navigationPane.push(page);
}
i think this will solve your issue and in the main.cpp page change the content as follows
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
qml->setContextProperty("_app", this);
root = qml->createRootObject<AbstractPane>();
app->setScene(root);
and
void Navigater::tr1()
{
Label *tryLabel1 = root ->findChild<Label*>("labelObj");
if(tryLabel1)
{
qDebug()<<"tttt "<<tryLabel1->text(); /////////////intial text
tryLabel1->setText("Hello!!!!!!!") ;
qDebug()<<"yyyy "<<tryLabel1->text(); ////////////changedText gets reflected on DeviceLog but not on UI
}
else
{
qDebug()<<"Not Found";}
}
you can navigate in qml easily without using c++
1.page1.qml
Page {
id: rootPage
Container {
background: Color.LightGray
layout: DockLayout {
}
Label {
text: "First page"
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
}
}
actions: [
ActionItem {
title: "Next page"
ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
var page = pageDefinition.createObject();
navigationPane.push(page);
}
attachedObjects: ComponentDefinition {
id: pageDefinition
source: "PageTwo.qml"
}
}
]
}
onPopTransitionEnded: {
page.destroy();
}