Building a new static html view by selecting a new request in the language menu - html

When developing a multi language website in ASP.NET, I read a lot of things like; routing, localization and CultureInfo. My basic knowledge about ASP.NET with MVC5 doesn't allow to go through with these advanced skills. As well, the project for this restaurant, doesn’t need to be that advanced. It just need to load the correct language request with the new static html from the selected language through a new HomeController or whatever is needed.
My Project is currently online and when selecting French a new Index is loaded >>https://www.grandcafelamot.be/Language/Change?LanguageAbbrevation=fr. The same Index is been loaded for 'Nederlands', but this an issue I should solve later, I guess. But as I said, my main problem for the moment is, when selecting a language in the topbar language menu. From where can I build up a new Index and render it with the prober Body.
A second thing is that you've maybe noticed, I was capable to translate the topbar menu by resources when selecting French. Though, when clicking by example on Service-FR I am not able to load the new request Index with the correct language of this Link (Service-FR).
I've been searching so much to find a simple solution.
Thank you for reading my post and may be put me on the right way.

I'm not sure this is what you want. But you can return a different View based on a language setting. Then you simply need to create an additional cshtml file in the correct language, in this case the index-fr.cshtml.
public ActionResult Index()
{
var model = new Models.HomeViewModel();
if (MijnTaal == "nl-NL")
{
return View(model);
}
else
{
return View("index-fr", model);
}
}
Or write a simple method for it so you do not need to write those if/else statements every time.
public string getAction()
{
string action = ControllerContext.RouteData.Values["action"].ToString();
if (MijnTaal == "nl-NL")
{
return action;
}
else
{
return action + "-fr";
}
}
And then
return View(getAction(), model);

Related

WindowsPhone CreateBindingSet testing

I am now moving from my code behind xaml dp binding to using CreateBindingSet, as I believe it will be easier to maintain on long run. Previously to confirm that I haven't missed any binding, I had a Windows Phone Test project with a generic test routine - that would parse a view for all the controls, and confirm that each has a correct binding. I did this using
element.GetBindingExpression(dependencyProperty) // from System.Windows
and that's worked beautifully - validating all my views.
But now as I am changing over, all these tests are failing. Has anyone any suggestions on how I can test same thing with when the binding is applied using CreateBindingSet and .Apply.
Thanks in advance.
Rana
Reasoning behind the Madness
Being a lazy sod, I dream of a day where my View would be shared across all platforms; until then, the following would do (I have most in place and working)
BoilerPlate class that would be shared between all platforms:
#if __IOS
... needed namespaces
#else ....
public partial class FirstView
{
private new FirstViewModel ViewModel
{
get { return (FirstViewModel)base.ViewModel; }
}
private void CommonBinding()
{
var set = this.CreateBindingSet<FirstView, FirstViewModel>();
// do common bindings
set.Bind(PageText).For(c => c.Text).To(vm => vm.PageText).OneTime();
set.Apply();
}
}
Then View in Touch would be:
public partial class FirstView : MvxViewController
{
public override void LoadView()
{
// create
}
public override ViewDidLoad()
{
CommonBinding();
}
}
In theory, Views in other platform would be almost similar; just different inheritance (MvxActivity with OnCreate, and OnViewModelSet)/(MvxPhonePage with xaml/alternative, and Loaded Event for binding).
Finally, a common testing way to ensure that all the items has binding set somehow. In my mind, until autoview is supported in wp8, it's just the way to have as much shared code as possible.
I have just started on droid, and trying to make the layout compatible with xibFree, which I have already used in my touch project. If this works, I can then have shared layout between droid and touch (perhaps I should be looking at autoView anyway)
I'm personally not sure what value these tests add that much value to your application - these feel like they are operating at a level of "duplicating code" rather than actually testing any functionality.
However, this is very much down to personal opinion, and if you do want this level of testing, then I think you could do this by:
Inherit a class from https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.BindingEx.WindowsPhone/WindowsBinding/MvxWindowsBindingCreator.cs
Override ApplyBinding so that you can capture at test time the calls made for each element
Register this class with ioc as the IMvxBindingCreator in your test harness
Use the captured lists of binding requests in your tests

Wordpress―run JS after Widget was created in Admin panel

I am developing a Wordpress Theme that includes a custom Widget, everything works out fine but there is one thing I do not know how to implement correctly:
I would like to run some Javascript after the Widget Instance was created in the admin panel, that means in the very moment after the widget was dropped in a sidebar, not after saving.
I have no Problems with running JS after the page was loaded or the Widget was saved, I want to run Javascript after the User just dropped a new Instance into the side bar, what actually can happen more than once without page reload.
Greetings philipp
Another way of doing this I just figured out --
I'm going to show a more complex example involving dependencies, though realise the bit in Custom_Widget::form() is the real answer to the question:
function add_js_deps() {
if (is_admin()) {
wp_enqueue_script('jquery-ui-accordion');
}
}
add_action( 'init', 'add_js_deps' ); // "init" because wp_enqueue_scripts is too late.
// Then in the widget....
class Custom_Widget extends WP_Widget {
public function form($instance) {
/** Collapsing accordion-y form HTML here **/
wp_enqueue_script('custom-js', plugins_url('js/my.js', __FILE__), array('jquery-ui-accordion'), '1.0.0', true);
}
}
I'd argue this is the better route as it has dependency management and you won't have a bunch of JavaScript mid-way into your DOM. Using wp_enqueue_script is generally always the more WordPressian way of doing things regardless.
Place a script tag in the widget form function.
function form($instance)
{
?><script type="text/javascript">console.log("firing javascript");</script>
<?php
//form details...
}
I eventually went a different way with this. Loaded our plugin admin script on the page using wp_enque_script and then just used jquery selectors and an event handler to target the right widget.
$('div.widgets-sortables')
.on('sortstop', function (event, ui) {
// only if this widget has the proper identifier...do something
if (ui.item.find('.my_widget').length == 0)
return;
run some function...
Still not my favourite technique...but it is cleaner then coding it in the widget. Does require a variable to track created widgets and using the "this" variable is useful

View instantiating another view

I'm separating my code similar to MVC (models, views, and controllers).
Let's say I have two view classes, one is conceptually a page (contains many items) and another is just a widget (like a list of recent news).
Here are the ways I see of doing it:
The controller instantiates both the page and widget classes, then passes the widget object into the page. If the page has a lot of widgets, I'd have to figure out how to pass it all in without it being confusing.
class PageController {
function foo() {
Widget widget1 = new Widget();
Widget widget2 = new Widget();
Page page = new Page(widget1, widget2);
}
}
class Page {
function Page(Widget widget1, Widget widget2) {
//do something with the widgets
}
}
The page instantiates the widget class. But now the page class has references to all sorts of views instead of being able to place the view where ever as long as it has the appropriate interface.
class PageController {
function foo() {
Page page = new Page();
}
}
class Page {
function Page() {
Widget widget1 = new Widget();
Widget widget2 = new Widget();
//do something with the widgets
}
}
Something else?
What is your advice and why?
Thank you.
I actually side with approach 1 in some ways. I would say Page should be able to be instantiated with or without widgets. You can add a collection of widgets to begin with and/or one at a time through some other provision within the Page as you run through your business logic and rules.
This gives you more flexibility to modify the construction of page as you go.
Widgets contain information on how they function and their presentation within the layout of the page.
Page should only be responsible for getting the information/instructions from the contained widgets and initialize/render them.
This will allow for a more flexible and fluid design.
Conceptually, #2 makes the most sense to me.
It's perfectly fine to have coupling between views if one type of view contains another. For example, it should be the page's job to manage where to place each widget, when to hide certain widgets etc.
However, the page shouldn't care about events pertaining to those widgets unless it needs to. If a widget has a button, it should just callback to a controller and skip telling the page... unless it causes the widget to be resized and the page needs to lay things out differently.
Hopefully this is useful to you.

create a link that opens a page and runs a function contained in the link

I am still learning PHP so my question may seem a little obvious but...
My question relates to opencart but is probably quite a common practice on many websites. I am creating a opencart module and in that module i have several buttons that complete different tasks. Now I have assigned the button the correct 'href' with the path and appropriate action. eg
$this->data['dosomething'] = $this->url->link('module/modulename/dosomething', 'token=' . $this->session->data['token'], 'SSL');
Note: I have called the module and action a general name for the purposes of my question.
In the controller I then have a private function called 'index', followed by a private function called 'dosomething' like below
public function index() {
* insert code *
}
public function dosomething() {
*insert code*
$this->redirect($this->url->link('module/modulename', 'token=' . $this->session->data['token'], 'SSL'));
}
Now, I would like to know how do I get the button to direct to the module controller and then run the 'dosomething' function. I could put something information in the link, ie action=dosomething and do it this way but most of opencart simply uses the text of the last / as the action. If I use the href stated above I get a error as it is trying to find the controller and template located in 'module/modulename/dosomething' rather than the controller and template located in 'module/modulename' USING the function 'dosomething'.
I hope this makes sense. I see that many other scripts in opencart successfully use this method but I just cant figure out how? I am sure I missing something obvious.
What you are doing is correct. OpenCart's framework will use the third piece of the route if specified as the method. If you try
public function dosomething() {
die('OK');
}
Then go to the url you've got, it should just show a blank white page with OK written on it. My guess is the error doesn't actually relate to the controller being an issue, and more to do with something else you've done. Either that, or the method and the third part of the route aren't a match, or the dosomething method isn't public

Preload dynamically created views in Actionscript for Flex Mobile App

I've got the following problem, my boss wants me to make our app far more responsive without any waiting time between switching views. It used to a "standard" application based on a ViewNavigator but with just one View that was destroyed and re-created with different content based on the user's selection of tabs he created himself. Views were switched with the default SlideViewTransition. I'm down to half a second now with a slightly more lightweight approach as described below, however that half second is still too much.
The app is a tabbed application where the user can create and edit new views himself, so create/edit/delete tabs and their corresponding tabs.
My current implementation is based on a ButtonBar and a Group that is used to display the "views". The group's content is created based on the selected tab. The content is based on XML data that stores all the required information to build the "view". Naturally, removing and creating the component's takes a little while (the half second I talked about), so I'm after another solution.
What I thought about is using the ViewNavigator and create all stored views upon application start.
Very much like this:
for each (var _view:XML in _allViewsConfig.children()) {
var compView:View = new View();
compView.percentHeight = 100;
compView.percentWidth = 100;
compView.name = _view.label;
for each (var _groupElement:XML in _view.vgroup) {
var group:VGroup = new VGroup;
group.percentWidth = 100;
group.percentHeight = 100;
for each (var _windowElement:XML in _groupElement.window) {
var window:WindowContainer = new WindowContainer;
for each (var _componentElement:XML in _windowElement.component) {
var component:UIComponent = _componentManager.create(_componentElement.#type, _componentElement);
window.addElement(component);
}
group.addElement(window);
}
compView.addElement(group);
}
views.addItem(compView);
}
views is an ArrayList that is used to store the created views.
The only problem I've got right now is that I can't use the Views stored in this ArrayList in the corresponding ViewNavigator.
I tried it the usual way, i.e. navigation.pushView(_viewCreator.views.getItemAt(0) as Class);
This, however doesn't work, no error or anything, the ViewNavigatorjust doesn't do anything, so I guess that a View class can't be created like this.
So how can I make this work?
Also, do you guys think that this is a proper solution to the problem, especially considering the whole dynamic nature of the application (being based on tabs)?
Naturally, slide transitions will be completely disabled as they are quite slow with our complex components.
Any help, comments or thoughts would be greatly appreciated!
EDIT:
On second thought, simply using Groups instead of ViewNavigator and View should make this a little more lightweight and solve the issue of views not being pushed.
In fact ViewNavigator pushView() is a mechanism which create an instance of a given Class (method parameter).
For all navigation history purpose, ViewNavigator uses NavigationStack objects to store relevant values (that you can customize too).
I don't have a straightforward answer for you, but I think you'll have to implement your own custom ViewNavigator mechanism (extending ViewNavigator to leverage existing useful methods and override others).