Jhipster - use of isInAnyRole - jhipster

I have set up several roles in MySql, and I want to use the function
isInAnyRole in navbar.html in order to display a menu for users with roles 'ROLE_USER' and ROLE_SUPERVISOR'.
I have replace isInRole('ROLE_USER') by isInAnyRole(['ROLE_USER','ROLE_SUPERVISOR']).
But isInAnyRole is not called and none of the menus are displayed.
What is the good way to use isInAnyRole function?
Thanks
<ul class="nav navbar-nav nav-pills">
<li ng-switch-when="true" class="dropdown-hover" ng-class="{active: $state.includes('user')}" ng-show="isInAnyRole(['ROLE_USER','ROLE_SUPERVISOR'])">
and
isInAnyRole: function (roles) {
if (!_authenticated || !_identity.roles) {
return false;
}
for (var i = 0; i < roles.length; i++) {
if (_identity.roles.indexOf(roles[i]) !== -1) {
return true;
}
}
return false;
}

You're using an old version of JHipster, since release 2.7.0 we provide a directive authority.directive.js which does exactly what you want. You should consider upgrading your app.

Related

How can I add a search button to this existing accordion search code?

I am using the code by Rick Sibley from the first answer on this post: Search within an accordion
Rick mentions that a search button can be added to run the script onclick, in addition to pressing enter to submit and run the search script. Can any body help me add the search 'button' functionality to this, please?
Thanks so much!
I figured it out! I feel like a genius - though I am obviously very bad at this.
Here's what I added in addition to the keyup event listener:
//Search Accordings; Highlight & Open Matching Areas ON SEARCH BUTTON CLICK
function searchBtn() {
var input, filter, i, acc, panels, txtValue, searchText, searchTitle;
input = document.getElementById("keywordSearch");
filter = input.value.toUpperCase();
acc = document.getElementsByClassName("accordion");
panels = document.getElementsByClassName("panel");
for (i = 0; i < panels.length; i++) {
for (i = 0; i < acc.length; i++) {
searchText = panels[i].textContent || panels[i].innerText;
searchTitle = acc[i].textContent || acc[i].innerText;
if (input.value !== "") {
if (searchText.toUpperCase().indexOf(filter) > -1 || searchTitle.toUpperCase().indexOf(filter) > -1) {
if (!acc[i].classList.contains("active")) {
acc[i].classList.add("active");
}
highlightIndex.apply(filter);
panels[i].style.maxHeight = panels[i].scrollHeight + "px";
panels[i].scrollIntoView({
behavior: 'smooth'
});
} else {
if (acc[i].classList.contains("active")) {
acc[i].classList.remove("active");
}
panels[i].style.maxHeight = null;
}
} else {
highlightIndex.remove();
if (acc[i].classList.contains("active")) {
acc[i].classList.remove("active");
}
panels[i].style.maxHeight = null;
}
}
}
}
With the following button added in html
<button type="submit" id="searchBtn" onclick="searchBtn();">Search</button>

Moodle 2.7 - Update core_renderer.php not applying changes - Custom menu

I am developing a custom theme based on bootstrap for moodle 2.7. I am adding a simple class to the custom menu function (render_custom_menu) on line 80. I simply addded the navbar-right class that is applied to the standard menu shown in both code blocks below.
Custom menu:
protected function render_custom_menu(custom_menu $menu) {
global $CFG, $USER;
// TODO: eliminate this duplicated logic, it belongs in core, not
// here. See MDL-39565.
$content = '<ul class="nav navbar-nav navbar-right">';
foreach ($menu->get_children() as $item) {
$content .= $this->render_custom_menu_item($item, 1);
}
return $content.'</ul>';
}
Standard Menu:
protected function render_user_menu(custom_menu $menu) {
global $CFG, $USER, $DB;
$addusermenu = true;
$addlangmenu = true;
$langs = get_string_manager()->get_list_of_translations();
if (count($langs) < 2
or empty($CFG->langmenu)
or ($this->page->course != SITEID and !empty($this->page->course->lang))) {
$addlangmenu = false;
}
if ($addlangmenu) {
$language = $menu->add(get_string('language'), new moodle_url('#'), get_string('language'), 10000);
foreach ($langs as $langtype => $langname) {
$language->add($langname, new moodle_url($this->page->url, array('lang' => $langtype)), $langname);
}
}
if ($addusermenu) {
if (isloggedin()) {
$usermenu = $menu->add(fullname($USER), new moodle_url('#'), fullname($USER), 10001);
$usermenu->add(
'<span class="glyphicon glyphicon-off"></span>' . get_string('logout'),
new moodle_url('/login/logout.php', array('sesskey' => sesskey(), 'alt' => 'logout')),
get_string('logout')
);
$usermenu->add(
'<span class="glyphicon glyphicon-user"></span>' . get_string('viewprofile'),
new moodle_url('/user/profile.php', array('id' => $USER->id)),
get_string('viewprofile')
);
$usermenu->add(
'<span class="glyphicon glyphicon-cog"></span>' . get_string('editmyprofile'),
new moodle_url('/user/edit.php', array('id' => $USER->id)),
get_string('editmyprofile')
);
} else {
$usermenu = $menu->add(get_string('login'), new moodle_url('/login/index.php'), get_string('login'), 10001);
}
}
$content = '<ul class="nav navbar-nav navbar-right">';
foreach ($menu->get_children() as $item) {
$content .= $this->render_custom_menu_item($item, 1);
}
return $content.'</ul>';
}
I'm not sure why this change is not taking effect. Anyone have experience with this and how to solve it. I'm sure I'm overlooking something very simple.
FYI: I have purged the moodle cache many times, reset the server and cleared the history in the browser.
Thanks!

Dialog Updates in Primefaces

I read in the Primefaces forum that updating dialogs in direct way or updating encircling elements should be avoided since the instances are duplicated and other strange behaviours.
But we have some kind of a special case and would really need to update an element that contains lot of dialogs.
Is there really no way to do this in a same way without getting duplicated instances? How does it come to the duplicated instances? Could it be that this only happens when appendToBody is set to true because it is updated and shifted once more to the body instead of just being updated?
A solution is to fix the dialog.js, see Primefaces forum.
For Primefaces 3.4.1:
PrimeFaces.widget.Dialog.prototype._show = function() {
if(this.cfg.showEffect) {
var _self = this;
this.jq.show(this.cfg.showEffect, null, 'normal', function() {
_self.postShow();
});
}
else {
//display dialog
/*Begin Custom Code*/
var dlg = jQuery(this.jqId);
if(dlg.size() > 1){
dlg.last().remove();
}
this.jq = dlg;
/*End Custom Code*/
this.jq.show();
this.postShow();
}
this.focusFirstInput();
this.visible = true;
this.moveToTop();
if(this.cfg.modal)
this.enableModality();
}
The dialog was reimplemented in v3.0. I think there are no problems now.
For Primefaces 3.5
PrimeFaces.widget.Dialog.prototype._show = function() {
this.jq.removeClass("ui-overlay-hidden").addClass("ui-overlay-visible").css({display:"none",visibility:"visible"});
if(this.cfg.showEffect){
var a=this;
this.jq.show(this.cfg.showEffect,null,"normal",function(){
a.postShow();
});
}
else {
//display dialog
/*Begin Custom Code*/
var dlg = jQuery(this.jqId);
if(dlg.size() > 1){
dlg.first().remove();
}
this.jq = dlg;
/*End Custom Code*/
this.jq.show();
this.postShow();
}
this.moveToTop();
if(this.cfg.modal){
this.enableModality();
}
}

Firefox gBrowser.getBrowserForTab but no gBrowser.getTabForBrowser?

In the Javascript for a Firefox extension, you can call gBrowser.getBrowserForTab but there is no gBrowser.getTabForBrowser. So I wrote my own and it works, and I'm just curious if there's any reason I shouldn't be doing this, or if there's anything wrong with the code. The following is in my init method that gets called when the window loads.
gBrowser.getTabForBrowser = function(browser) {
for (var i=0; i<gBrowser.browsers.length; i++) {
if (gBrowser.getBrowserAtIndex(i) === browser) {
return gBrowser.tabContainer.getItemAtIndex(i);
}
}
return null;
}
(or should it be gBrowser.prototype.getTabForBrowser = ...?)
Far as I know there is no built in getTabForBrowser function, so you would have to roll your own. However, your code assumes that browser nodes are stored in the same DOM order as tab nodes. I can't say for sure if this assumption is ever broken, but considering tabs can be re-positioned by the user arbitrarily, it is not something I'd rely on.
Fortunately, each tab object has a linkedBrowser property. So you could rewrite your code like so:
gBrowser.getTabForBrowser = function(browser) {
var mTabs = gBrowser.mTabContainer.childNodes;
for (var i=0, i<mTabs.length; i++) {
if (mTabs[i].linkedBrowser == browser) {
return mTabs[i];
}
}
return null;
}

Huge Web App With Memory Leak in IE 6

I have a huge web app that is having issues with memory leak in IE 6.
Fixing a memory leak in a 5 line code sample that demonstrates the problem is easy.
But if I have a very huge application, where should a start from?
Check out Drip. That usually takes the guesswork out of IE memory leaks.
If for some reason Drip doesn't find it, take a close look at any JavaScript code that works with events. That is almost always the source of any significant memory leak in a browser.
Destroying a DOM element with handlers attached to it, without removing those handlers first, will prevent the memory associated with those handlers from being recovered.
Does the application use a lot of JavaScript?
If it does, then one thing I've found that helps for avoiding memory leaks is to make sure you're using a JavaScript framework such as Prototype or jQuery because they have tried and tested event-handling code that doesn't leak memory.
IE6 can also leak memory if you have circular references to DOM objects
Also try this JavaScript Memory Leak Detector and see if you can diagnose where the problem is
Here is how I solved the memory leak problem in IE7. The idea is to dispose/set to null all expando-properties on all DOM nodes at unloading the page. This worked for me. You may find it useful.
<!--[if lt IE 8]>
<script type="text/javascript">
function disposeAll() {
if (window.document.all) {
for (var index = 0; index < window.document.all.length; index++) {
try { dispose(window.document.all[index], []); } catch (e) { debugger; }
}
}
dispose(window.document.body, []);
dispose(window.document, []);
dispose(window, []);
window.disposeAll = null;
window.dispose = null;
window.onunload = null;
}
function dispose(something, map) {
if (something == null) return;
if (something.dispose && typeof (something.dispose) == 'function') {
try { something.dispose(); } catch (e) { debugger; }
}
map.push(something);
for (var key in something) {
var value = null;
try { value = something[key]; } catch (e) { };
if (value == null || value == dispose || value == disposeAll) continue;
var processed = null;
for (var index = 0; index < map.length; index++) {
if (map[index] === value) {
processed = value;
break;
}
}
if (processed != null) continue;
var constructor = value.constructor;
if (constructor == Object || constructor == Array) {
try { dispose(value, map); } catch (e) { debugger; }
}
if (constructor == Object || constructor == Array || constructor == Function) {
try { something[key] = null; } catch (e) { debugger; }
}
}
map.pop();
}
(function() {
var previousUnloadHandler = window.onunload;
if (previousUnloadHandler == null) {
window.onunload = disposeAll;
} else {
window.onunload = function() {
previousUnloadHandler.apply(this, arguments); // <== HERE YOU MAY WANT TO HAVE AN "IF" TO MAKE SURE THE ORIGINAL UNLOAD EVENT WASN'T CANCELLED
disposeAll();
previousUnloadHandler = null;
};
}
}());
</script>
<![endif]-->
You may want to remove all "debugger;" statements if you don't feel like dealing with some occasional exceptions.

Resources