Dart menu depending on user logged

Sett 105 ganger
Hopp til første uleste melding

Mateusz Lewandowski

ulest,
11. juni 2016, 12:13:4111.06.2016
til 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

ulest,
14. juni 2016, 12:33:2214.06.2016
til 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

ulest,
18. juni 2016, 15:09:3818.06.2016
til 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

ulest,
5. juli 2016, 13:42:4305.07.2016
til 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?
Svar alle
Svar til forfatter
Videresend
0 nye meldinger