Dart menu depending on user logged

105 views
Skip to first unread message

Mateusz Lewandowski

unread,
Jun 11, 2016, 12:13:41 PM6/11/16
to Dart Misc
Hi.
I have a polymer core-menu with core items.
I would like to define which options should be vissible depends on user would by logged or not.
I think that it could be done by dynamic created CoreItems in dart like
CoreItem item=new CoreItem('core-item')
but i do not know how it could be added to core-menu defined in html,
Following is what i acctually have.
Please help and give me some advice.

dart:

@CustomTag('menu-element')
class Menu extends PolymerElement {
// Menu.created() : super.created();
@observable int isLogged;
Menu.created() : super.created()
{
if(window.localStorage['authentication'] !=null)
{
this.isLogged=1;
}
}

void SelectItem(event, detail, target)
{
if(detail['isSelected'])
{
var command=detail['item'].label;
print(detail['item'].label);

switch(command)
{
case 'Ogloszenia':
window.location.assign("index.html");
break;
case 'Logowanie':
window.location.assign("login.html");
break;
case 'Rejestracja':
window.location.assign("register.html");
break;
default:
print("Error");
}
}

}
}

html:

<polymer-element name="menu-element">
<template>
<core-menu on-core-select="{{SelectItem}}">
<core-item icon="dialog" label="Ogloszenia" id="advertisments"></core-item>
<core-item icon="settings" label="Logowanie" id="logon"></core-item>
<core-item icon="search" label="Rejestracja" id="register"></core-item>
<core-item label="Dodaj ogloszenie"></core-item>
</core-menu>
</template>
</polymer-element>

Adam Stark

unread,
Jun 14, 2016, 12:33:22 PM6/14/16
to Dart Misc
You don't specify Polymer >1.0 or Polymer-pre 1.0, but I'll assume pre-1.0 by the @observable tag.

The more "Polymeric" way to do it would be to add a hidden attribute to each core-item based on the isLogged state, e.g. <core-item hidden?="{{isLogged}}"> or <core-item hidden?="{{!isLogged}}"> 

In >1.0, it's the same except use hidden$ instead of hidden? and @Property(notify: true) instead of @observable

--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

Mateusz Lewandowski

unread,
Jun 18, 2016, 3:09:38 PM6/18/16
to mi...@dartlang.org
thanks a lot, it works, 
I have found the following which looks smart but does not work for my case.
Do you know why?

<dom-module id="my-element">
<template>
<template is="dom-if" if="{{showAnswer}}">
<div>42</div>
</template>
<template is="dom-if" if="{{!showAnswer}}">
<div>
What is the answer to "The Ultimate Question of Life, the
Universe, and Everything"?
</div>
</template>
<button on-tap="toggleView">{{buttonText(showAnswer)}}</button>
</template>
</dom-module>

Adam Stark

unread,
Jul 5, 2016, 1:42:43 PM7/5/16
to mi...@dartlang.org
Sorry for the late reply.

Those are polymer > 1.0 style tags, so first are you sure you're using the correct version? There were a number of changes and my Polymer pre-1.0 is a bit rusty. What's the .dart file look like?
Reply all
Reply to author
Forward
0 new messages