Discussion:
[dart-misc] Dart menu depending on user logged
Mateusz Lewandowski
2016-06-11 16:13:40 UTC
Permalink
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>
--
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+***@dartlang.org.
Adam Stark
2016-06-14 16:33:09 UTC
Permalink
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

On Sat, Jun 11, 2016 at 9:13 AM Mateusz Lewandowski <
Post by Mateusz Lewandowski
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.
@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)
{
window.location.assign("index.html");
break;
window.location.assign("login.html");
break;
window.location.assign("register.html");
break;
print("Error");
}
}
}
}
<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>
--
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
--
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+***@dartlang.org.
Mateusz Lewandowski
2016-06-18 19:09:33 UTC
Permalink
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>
Post by Adam Stark
You don't specify Polymer >1.0 or Polymer-pre 1.0, but I'll assume pre-1.0
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
On Sat, Jun 11, 2016 at 9:13 AM Mateusz Lewandowski <
Post by Mateusz Lewandowski
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.
@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)
{
window.location.assign("index.html");
break;
window.location.assign("login.html");
break;
window.location.assign("register.html");
break;
print("Error");
}
}
}
}
<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>
--
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
--
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
--
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+***@dartlang.org.
Adam Stark
2016-07-05 17:42:29 UTC
Permalink
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?

On Sat, Jun 18, 2016 at 12:09 PM Mateusz Lewandowski <
Post by Mateusz Lewandowski
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>
Post by Adam Stark
You don't specify Polymer >1.0 or Polymer-pre 1.0, but I'll assume
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
On Sat, Jun 11, 2016 at 9:13 AM Mateusz Lewandowski <
Post by Mateusz Lewandowski
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.
@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)
{
window.location.assign("index.html");
break;
window.location.assign("login.html");
break;
window.location.assign("register.html");
break;
print("Error");
}
}
}
}
<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>
--
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
--
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
--
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
--
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+***@dartlang.org.
Loading...