public/js/views/role.js in conjur-asset-ui-1.3.0 vs public/js/views/role.js in conjur-asset-ui-1.3.1

- old
+ new

@@ -1,41 +1,56 @@ /** @jsx React.DOM */ +/* global conjur, React, _ */ -/** render a link to the role represented by this.props.id - Example: <RoleLink id="ci:user:jon"/> -*/ -var RoleLink = React.createClass({ - render: function() { - var tokens = this.props.id.split(":"); - var kind = tokens[1]; - var id = tokens[tokens.length-1]; - if (tokens.length==1) { // just username - kind="user"; - id=tokens[0]; - } +(function(conjur, React, _) { + 'use strict'; - // TODO: shouldn't point to unknown types - var href = "/ui/" + conjur.utils.pluralize(kind) + "/" + encodeURIComponent(id); - var classes = ["role-link"]; + /** render a link to the role represented by this.props.id + Example: <RoleLink id='ci:user:jon'/> + */ + this.RoleLink = React.createClass({ + render: function() { + var tokens = this.props.id.split(':'), + kind = tokens[1], + id = tokens[tokens.length-1]; - var known_types=['user','group','layer','host','policy']; - var kind_is_known = _.contains(known_types, kind); - var text = id; + if (tokens.length === 1) { // just username + kind = 'user'; + id = tokens[0]; + } - if( !this.props.noIcon ) { - if (kind_is_known) { - classes.push(kind); - } else { - classes.push('abstract'); // we have no picture for abstract role yet - if (text==id) { - text=[kind,text].join(":"); // prepend kind to id + // TODO: shouldn't point to unknown types + var href = '/ui/' + conjur.utils.pluralize(kind) + '/' + window.encodeURIComponent(id); + + var classes = ['role-link'], + knownTypes = ['user','group','layer','host','policy'], + kindIsKnown = _.contains(knownTypes, kind), + text = id; + + if (!this.props.noIcon) { + if (kindIsKnown) { + classes.push(kind); + } else { + classes.push('abstract'); // we have no picture for abstract role yet + + if (text === id) { + text = [kind, text].join(':'); // prepend kind to id + } + } + } else if (text === id) { + text = [kind, text].join(':'); // prepend kind to id } + + return ( + <a className={classes.join(' ')} href={href}> + {text} + </a> + ); } - } else if (text==id) { - text=[kind,text].join(":"); // prepend kind to id - } + }); - return <a className={classes.join(' ')} href={href}> - {text} - </a>; - } -}); +}).bind(conjur.views) +( + conjur, + React, + _ +);