How do I add a new menu to an aspnetboilerplate based project? - asp.net-mvc

This has been asked before but I'm going to be more precise with my question to hopefully get a better answer:
I have figured out how to add views to the PageNames class:
public const string WorkOrders = "WorkOrders";
and then to the projectNavigationProvider class to get them in to the navbar:
.AddItem(
new MenuItemDefinition(
PageNames.WorkOrders,
L("WorkOrders"),
url: "WorkOrders",
icon: "business",
requiredPermissionName: PermissionNames.Pages_WorkOrders
)
To get my main views added to the main navbar and working properly.
However, I have not figured out how to create a totally new menu to be used elsewhere. In the app I'm working on we have several pages that display all of the records in a particular table, Work Orders for example. But each record in each table should have several links to other pages for create, edit, details and delete.
One of my partners seems to have solved this problem on other pages by using modals and ajax calls to the controllers endpoints. It works fine for the Customers, which only require name and contact info., but I don't think a modal will work for creating, viewing or editing a Work Order becuse it requires adding line items and the associated data for each one of them etc... There's a lot to it. Lastly, it doesn't seem like the template is set up to be used that was as he wrote a lot of his own js to get it working.
Currently, the create, edit, and details views exist and I have links to them next to each record but I get errors when I try to use the link. Maybe I don't understand how the routing works? In the normal mvc template from VS the links have properties for specifying the controller and method and mvc handles the rest.
<a asp-action="Edit" asp-route-id="#item.WorkOrderID">Edit</a> |
<a asp-action="Details" asp-route-id="#item.WorkOrderID">Details</a> |
<a asp-action="Delete" asp-route-id="#item.WorkOrderID">Delete</a>
I'm getting the same error I had when trying to get the Work Orders page to load but had not added it to pagenames or navigationprovider, which makes me thing I just need to add the links to the navigationprovider class but I don't want a link the the WordOrders create page on the main menu, I want it on a mini menu next to the corresponding record. I have added the page to the pagenames class but am not sure how to create a separate menu for my main page.
public const string CreateWorkOrders = "CreateWorkOrders";
In reviewing the navigationprovider class I see:
context.Manager.MainMenu
and I'm thinking I must be able to create another menu and add items to it like this:
context.Manager.NewMenu.AddItem(....
but it looks like MainMenu is referenced in a class that I can't find or edit. Should I be creating another class defining the NewMenu so I would be able to configure it in the existing navigationprovider class or should I be creating a separate navigationprovider class for it?
Hopefully I've convinced everyone who looks at this that I have done plenty of research before reaching out for help. Even a link to some more detailed documentation would helpful.

You can add a new menu like this:
context.Manager.Menus.Add(WorkOrders, new MenuDefinition(WorkOrders, L(WorkOrders)));
Usage:
context.Manager.Menus[WorkOrders].AddItem(...)

Related

Can't select page layout when creating a new page in Rails alchemy-cms

I'm new to alchemy-cms.
I created a fresh install from the guides. I did not add any concept or structure.
Going to localhost:3000 I have to add the first user and after that I have a clean site.
When trying to add a new page, I have to select a type (page-layout?) and type in a name.
The Type combobox remains empty, and therefore the website don't allow me to add a page. What am I doing wrong? I think I'm missing something very obvious here.
I have looked allready in the source code, and running the following:
rails console
Alchemy::PageLayout.all
and this results in:
=> [{"name"=>"index", "unique"=>true, "elements"=>["article"], "autogenerate"=>["article"]}]
So I would guess the combobox should be filled with this item.
The index page layout is marked as unique, so it can only be added once per language. And as the so called language root page (the first most page in your page tree) already has this page layout, no new page can be created using this page layout.
In order to fix your problem you need to add another page layout to your page_layouts.yml file. It is good practice to add an standard page layout that is not unique (default) and can therefore be added multiple times per language.

Change CSS style using drop down menu in MVC

I'm trying to make a drop down menu that has a bunch of items (Amelia, Cerulean, Cosmo, Cyborg, Flatly, Journal). Each of these items represent a css file.
When one of them is selected I want my website to take this selected css file and apply it to the website.
I would like the drop down menu to interact with jquery, meaning when a item is selected jquery takes over and makes a asyn/ajax call to some mvc actionresult.
By the way I'm using MVC 5.
I hope someone can help me sketch the initial groundwork.
I've implemented this in my application.
I'm not sure what to tell you though. It's easier when we have an attempted solution to fix.
Here's an overview of how mine works:
I have created a controller called SharedController. The purpose of it is to contain various actions that render common actions. All of the actions are considered ChildActionOnly.
My _Layout uses RenderAction to render the action NavbarPartial which is in my SharedController.
More importantly the Navbar partial then uses RenderAction to render the action ThemeListPartial. This action is responsible for getting a list of available themes. The list of available themes is determined at applications startup. I've created a ThemeFinder class and ThemeRepository class that are responsible for finding and storing themes. The ThemeFinder finds themes by expressions that you give it. In a new class called App_Start/ThemeConfig I've given it only one expression - "~/Content/themes/{name}.bootstrap.css". This will find all themes with that naming convention in that location.
My razor code will take the ViewModel and display a dropdown menu in the navbar.
To get the themes to change my dropdown menu contains an AJAX link to an action called SaveTheme in ThemeController. This action takes a theme name as a string and tries to save it in a cookie for the user.
If the theme is found and saved successfully, the action responds with a success message.
jQuery then changes the theme by finding the associated link attribute and changing the HREF contents to the new theme. It knows the new theme relative URL because I have it stored in data attributes.
I completed this before I made the switch to AngularJs. The one thing I plan to go back and change is to cut out as much (maybe all) jQuery as possible and replace it with better code.

Where to put reusable HTML code in rails?

I'm writing a rails app that allows users to delete records of various sorts. After pressing a delete button, I'd like to show a confirm dialog using bootstrap. I'd like to use this same dialog in several of my views, so I'll need to include the same HTML snippet in most of my pages.
I'm new to rails and I'm still learning the conventions. Can anyone suggest the best (or standard) place to put the dialog code? Should it be a partial in views/layouts/_confirm_delete_dialog.html.erb, should it go inside application.html.erb, or should I put it somewhere else?
Thanks in advance for your advice,
D.
Within your Views folder, you can create a general folder (called whatever you want). If you have a variable that you need to pass through to the general layout, you can definitely do so, but you will want to make sure that the information that you're passing through doesn't cause conflicts with the fields pulled from the model. For example, if you have two models and one has a public field but the other doesn't then you will not want to have a generic message that is using the public field. However, something like the created_at or updated_at would be okay.
You would use a code similar to,
<%= render 'general/simple_message', :f => f %>
In your views folder, you would have a directory called general and a file called _simple_message.html.erb.

Creating ajax-enabled subform with "Edit" button

I am looking for the best way to create ajax enabled subforms from items in a list with MVC 3. A static list of values should be generated, but with an "edit" link/button next to every item, to toggle inline edits.
I did follow the tutorial at this link
http://blog.janjonas.net/2011-07-24/asp_net-mvc_3-ajax-form-jquery-validate-supporting-unobtrusive-client-side-validation-and-server-side-validation [1]
However it is based on the form edit fields always being visible
I'd like to show a static list with field values, but let the user activate an edit field by clicking "edit" (e.g. button)
I did modify the example at [1] by creating a default partial view with a form with submit button only. When posting the data by ajax the edit form will show. It looks like it is working, (I only need to hide validation errors on the first POST - which does not send real data).
Update:
An even better solution would probably be to leave out all forms in the static view, just have a single css class button/link next to each item, and let jquery fetch the relevant view for the clicked item. I am not sure how to do that with MVC 3+jQuery though.
Another update:
I discovered Ajax.Actionlink, which did exactly what I wanted!
I found out how to do it, and it turned out to be real simple!
I created two partial views.
One for rendering each static item. I used used Ajax.ActionLink with InsertionMode "replace", and set the parent of the item as the target
The second for rendering the form. Here I used Ajax.Beginform with similar options.
On successfully saved data, I returned the static view, on failure, I returned the partial view with the ajax form again.
I'm happy I found a MVC-centric way to do it (although it is fun creating custom stuff with jQuery)
It sounds like you need an inline editing plugin for jQuery. I would try jEditable. I have not used it myself but appears to have extensive docs.
this entry might help: code + video + explanation ;)
http://ricardocovo.wordpress.com/2011/04/03/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms/
-covo

Route rewriting in asp.net mvc

I'm having a really hard time understanding routing.
Please help me with this problem.
Each of my controllers have these three actions right now
Users have Index, Create and Edit
Locations have Index, Create and Edit
Companies have Index, Create and Edit
The thing is, it all gets done through ajax.
I have jquery ui tabs with two tabs for each, Create and Edit
So the Index method is always the one that gets called for action links.
and inside this main view is that you can call(by clicking on the tab icon) the other methods that return an ajax view that gets output into the jQuery tab (I hope that's clear)
I have a sidebar with links to the controllers. and to specific methods of these controllers. The wanted behavior is that it should actually go into the Index Method and then with some logic autoload the wanted tab.
It all works just fine right now. But my urls are horrible.
To get to the create method for Users I have to go this url
http://localhost/Users/Index/1
http://localhost/Users/Index/2
I want the behavior of these links to be remapped to these links
http://localhost/Users/Create
http://localhost/Users/Edit
So even though it seems as if you are calling the Create method of the controller you are actually always calling the Index method.... (I know how to transform Create into "1" and Edit into two, so don't worry about that part
Hope that's clear.
Thanks in advance
Edit:
Just realized that this might not be possible cause then when I actually need to call the methods (with ajax) it wont know what to do.... am I correct?
Without seeing your controller action, you should be able to add a route something like this:
routes.MapRoute("myroute","users/{option}",new {controller="Users",action="Index"});

Resources