I'm working in a VisualStudio project but I need help.
I have a database with the user information which includes a value to obtain the role. Depending that value, I need to change the page header to show/hide links and options, but I don't know how to make it.
Thanks in advance.
Easy way to implement what you want
void privilege ()
{
if(Session["role"].ToString() !="Admin")
{
//do somethings
}
else
{
//do other things
}
}
Related
We have some custom functions for managing the Cart (add entries, remove cart etc.) which often times takes place in the backend.
I am searching for a way to refresh the cart in Spartacus so that it can show the actual data without the need of reloading the whole page. This is noticeable in the Minicart count as well as when we navigate to the cartpage. There you can see that the Data is not up to date. When you reload the page (F5) then the right data gets loaded.
Does someone have any idea how to force reload the "current" cart? I say current, cause when we remove the cart in the backend, we would expect that "hidden" method to create a new cart and give that back to Spartacus without reloading the page.
I found some sort of solution which feels kinda wonky and somehow does not work 100%:
refreshCart(): void {
this.getUser().pipe(
map((usr) => {
return usr;
}),
map(usr => {
this.cartService.reloadCart(usr, "");
}
)
).subscribe()
}
getUser(): Observable<string | undefined> {
return this.userIdService.getUserId().pipe(
map((userid) => {
return userid;
})
);
}
We extended the ActiveCartService and added a new method "reloadCart" which loos like the follwing:
reloadCart(userId: string, cartId: string): void {
this.loadOrMerge(cartId, userId, userId);
}
Please note that this is my first Angular Project and i feel that i miss some of the concepts (most noticeable i struggle with the whole Observables / subscribe / pipe / map and everything surrounding that).
Thank you in advance.
Not sure what spartacus version you are using, but I believe it applies to most of the versions.
To force a reload of the cart, you can use the MultiCartService to use the loadCart method.
Or if you don't want to use the actual service, you can always dispatch the action on your custom service, which what the loadCart method does from MultiCartService. You just need to provide the userId and cartId.
new CartActions.LoadCart({
userId,
cartId,
})
I am not sure whether I broke the flow and introduced this bug. When I am editing a PO and confirming the PO (see Fig 2).
The changes get updated in database however the save button is still there. But the PO gets confirmed (See fig 3).
I need the save button to be replaced with "Edit" button (By default it was like that).
Can anyone suggest What could be wrong or any settings stuff??
Any help is appreciated..
In web addons-->web-static-src-->js-->view_form.js
add below lines of code:
on_button_save: function() {
var self = this;
var result = confirm("Do you want to save Record..?");
if (result==true) {
return this.save().done(function(result) {
self.trigger("save", result);
self.reload().then(function() {
self.to_view_mode();
var parent = self.ViewManager.ActionManager.getParent();
if(parent){
parent.menu.do_reload_needaction();
}
});
});
}
else{
return result;
}
},
This is the default behaviour to have the save button appear as it is if you did not click it and you clicked the button on the form.
Actually i written this code for my requirement.Before saving the record should ask the conformation to save.this code may help full you to further implements ion of you are requirement.
I have an edit page (in a DurandalJS single page app), where I use the .canDeactivate lifecycle method to check if there are any changes to the record, and optionally prompt them for confirmation before leaving the page.
I also have a 'Save' and 'View History' button. Is the correct thing to do to override the .canDeactivate method before calling router.navigate, to stop the modal popup invoking?
E.g.: As here:
self.onSave = function() {
self.repository.updateItem(self.model).done(function() {
self.canDeactivate = null; // Is this the correct way to do this?
router.navigate("#/home");
}
}
As this .canDeactivate will otherwise get called:
self.canDeactivate = function() {
if (!self.model.hasChanges()) {
return true;
}
return app.ShowMessage("Unsaved data will be lost", "Are you sure you wish to exit?", ["Yes", "No"]).done(function(result) {
return result !== "No";
}
};
Why dont you just set
self.model.hasChanges(false)
in your updateItem callback?
Then when your canDeactivate is called, it will return true.
Also you seem to have an error in your ShowMessage callback. I think you mean to do:
return result != "No";
I don't think the way Durandal decides whether to attempt to call a canDeactivate function is fully defined, other than the fact that if it's not in the view model, it won't try. Hence, even if it works as is, a future version of the framework could change its check to something like if (canDeactivate in viewModel) viewModel.canDeactivate(...); without further tests, and your code would break.
This is unlikely, but if you want to worry about it, you should thus delete self.canDeactivate instead of assigning it the null value.
Quote from the documentation:
To participate in the lifecycle, implement any (or none) of the
functions below on the object that you set the activator to (...)
Current implementation (activator.js, L126, 1eecbc2d3f84dc42eb7304bde761d88f300d8951):
if (item && item.canDeactivate) {
So it only checks if it's truthy (which would indicate using null works fine currently, too).
If you want to discuss the pattern, I don't see anything wrong with it, as long as it makes sense to you and everyone who should read the code.
You're not supposed to be activating and deactivating views programmatically in any critical path, so performance should be irrelevant either way (flag on view model or deletion of canDeactivate).
I have an ExtJS 4 grid with GroupingSummary Feature. ExtJs Default is grid is expanded when user clicks on any cell in grouping row. I want to disable this feature, no expansion should take place except when user clicks on designated 'expand' icon. How do I accomplish this?
There is the 'groupclick' event, is there a way to override its default behaviour and do nothing / remove it?
Thanks in advance
The method for it appears to be inherited from Grouping rather than GroupingSummary, so I suspect you need to override this method to prevent the current behaviour:
onGroupClick: function(view, group, idx, foo, e) {
var me = this,
toggleCls = me.toggleCls,
groupBd = Ext.fly(group.nextSibling, '_grouping');
if (groupBd.hasCls(me.collapsedCls)) {
me.expand(groupBd);
} else {
me.collapse(groupBd);
}
So you will need another file with something similar to the following:
Ext.require('Ext.grid.Grouping');
Ext.define('your.class.here', {
override: 'Ext.grid.Grouping',
onGroupClick: function() {
//do nothing
});
)};
Then you should be able to write a function that mimicks it was doing on groupclick, but instead on your icon click. Hope that helps.
I have an InfoPath Form built. What I am looking to do is have a reset button that clears and entire node of populated data. I have seen a few solutions out there but this seems like a relatively simple request of a page. Is there a quick way to reset an entire node to its default configuration?
Thanks in Advance!
Matt
This seems to have solved it.
private void ClearNode(XPathNavigator nodeToClear)
{
if (nodeToClear.HasChildren)
{
nodeToClear.MoveToFirstChild();
do
{
ClearNode(nodeToClear);
} while (nodeToClear.MoveToNext());
nodeToClear.MoveToParent();
}
else
{
nodeToClear.SetValue(string.Empty);
}
}
After that you just call whatever node you want cleared and pass it in as an XPathNavigator and away you go. It solved everything I was storing but I am curious how it would handle resetting fields with default values like a boolean or something.