Urent help Creating a Widget that the end user can interact with pretty pls!

Topics: Troubleshooting, Writing modules
Dec 11, 2011 at 9:17 AM

ARG!  I am beating head here for like 18 hrs over last 2 days, been like trying to run in a 4' pool of stucky mud...  I am sooooo close and fear I am going to have to walk in Monday with a NON result for all my labor...

Big picture:
I have a widget that needs to consider the users zipcode, and based on this provide a list of events within their area.
If the GeoIp lookup is off, or the users is interested in looking else where they can reach up and change the ZipCode to any of their choosing and "postback", having the modules redraw.

I have the widgets looking up from another DB and rendering just fine as a widget.
I have it all working just as I want..  I "think" what I want is for the

        protected override DriverResult Display(
            SeminarPart part, string displayType, dynamic shapeHelper) {

to be something I can bind to in the .cshtml

@model CustomPart

but no matter what I do I get ->

        The model item passed into the dictionary is of type 'IShapeProxyabb0e4251c0b4c71bfe70f2ec47bfca4', but this dictionary requires a model item of type 'Blah.Blah.MoreBlah.CustomPart'.

If I can get all of this happy, I "THINK" I would be able to do something like

        @Html.TextBoxFor(m=>m.SelectedZipCode)

And ultimately then the model would refresh its result set, changing the List<CustomData> in the model and redrawing the list...  ???

---

The DANGDED editor part exposes GET and POST DriverResult Editor and seems to do what I had hoped I could do here...   anyone, ideas?

PPPPPPLLLLLLEEEEEASSE Roger....  much thanks in advance, -James et 10-Geek dot com...
       


 

Developer
Dec 11, 2011 at 11:24 AM
Edited Dec 11, 2011 at 11:26 AM

The problem is that not a statically typed model is passed to the shape but a Clay object if you mimic the common implementation of drivers' Display() method. You can implement a statically typed shape just as for the editors (I suppose you know how to do this), but with a DisplayTemplate:

 

shapeHelper.DisplayTemplate( // Note that this is practically the same as with EditorTemplate
                    TemplateName: "Name",
                    Model: model,
                    Prefix: null)

 

This will display a shape template with the name Name.cshtml from your module's Views/DisplayTemplates directory and give it the model object "model". From the shape template you can then access this model just the same as in editor templates:

 

@model Namespace.SeminarPart
@Model.SeminarPartsProperty

Hope that puts out the fire :-).

Dec 12, 2011 at 12:15 AM
Edited Dec 12, 2011 at 12:16 AM

Thank you much, that did in fact get me past the hurdle, and I now am able to get the right "model" in play...

Perhaps I am just brain fried but now that I have 

        @Html.TextBoxFor(m=>Model.SelectedZipCode)

and perhaps something like..

        @Html.ActionLink("Update", "ChangeZip", "Seminars")

or better still, can I just wire up and or hack into the same update process/routes as the "editpart" does automagically ?

...

Now the right model is loaded, and I can/have code there, and or in the CustomDriver to repopulate the model.list<T> with the fresh data as per the zip code provided.. just not able to make sense of wiring in through the driver or perhaps through the IRoutes....???

..

Thank you much for your help!  -James

 


 

 


Dec 12, 2011 at 2:34 AM

It's not quite so simple. In the Display method you don't have access to an IUpdateModel, so there's no way to directly bind against the post data. In any case, there's no surrounding form like when building the editor.

What you need to do is just include your own form in the widget and post the results to a custom controller.

Dec 12, 2011 at 2:52 AM
Edited Dec 12, 2011 at 3:25 AM

I am sooo close!  Can you point me in a direction with this?  Is it all about the IRouteProvider to "post results to a custom controller" ?

Pretty sure, IRouteProvider hates me...  Like on a personal level...   Once I get to this custom controller, how do I get back again..

Let me backup, perhaps I am making this difficult.

My widget currently is dropable in Orchard, go that far.

My widget current takes a little data in the Admin side, and uses that then in the Driver to get a good ......Part..  This data uses EF4 to pull data from a non Orchard DB...  Works like a charm...

Last and final hurdle.  I don't have a clue how I am going to get a "good default ZipCode in the first place...  like..  Was hoping something about

 

 

 

 

        protected override DriverResult(SeminarPart part, string displayType, dynamic shapeHelper) -> would give me access to the "httpcontext?" that I might grab the IpAddress of my visitor and try to do some type of GeoIpLookup...  Anyway, lets assume we overcome this..

I have rendered 100 seminars to screen, yea!!!, all is good, Orchard is good.

Now..  the hangup...    User changes/adds their ZipCode and hits "update"...   I just need (something), perhaps the current ContentPartModel to take the new zipCode, and change the resulting list....

@Html.RouteLink
@Html.ActionLink
@using Html.Form(){}

...

I cannot be the first to come across this challenge, and am sucking hardcore to make friends with IRouteProvider....   What would you do / advise?

Thanks tons, -James

 

 

 

 

 

Dec 12, 2011 at 3:29 AM

You don't need an IRouteProvider to make a controller work. By default the url will be /ModuleName/ControllerName/ActionName. You only need to use IRouteProvider if you want to customise that route, use url parameters, etc.

I'm wondering why does this need to be a widget? It sounds to me more like a page.

You can access HttpContext thru WorkContext.

Dec 12, 2011 at 4:12 AM
Edited Dec 12, 2011 at 4:16 AM
I had everything working well as a page (rather an Orchard Module), then they decided it needed to be something that could be manually placed withing one of the 3 tabs at the bottom of a given page... Converting from a healthy Orchard Module, to a Widget didn't go so well, so I started over.. In fact in the last 3 days I have reinstalled from source 8 times.. :-( .... anyway, after starting over and creating a working widget, now I struggle to get it right... I am looking to write some good tutorials based on my journey, I am
not overly frustrated, just worried that I have to have this thing working by morning and am not looking forward to another 5am push...............
I am super appreciative of your help thus far. I am unfortunately a vetran to all development that != MVC, I have had success in the past with MVC 2 on crazy super simply apps...................
I would do about anything to have this done so I can get some sleep...  I have reached out to you in a private thread.  -James
Dec 12, 2011 at 5:54 AM

My paypal account is: pete.hurst@gmail.com

Best of luck, let me know if you need further assistance.

Pete

From: JamesIq [email removed]
Sent: 12 December 2011 05:13
To: pete@downplay.co.uk
Subject: Re: Urent help Creating a Widget that the end user can interact with pretty pls! [orchard:282543]

From: JamesIq

I had everything working well as a page, then they decided it needed to be something that could be manually placed withing one of the 3 tabs at the bottom of a given page... Converting from a healthy Orchard Module, to a Widget didn't go so well, so I started over.. In fact in the last 3 days I have reinstalled from source 8 times.. :-( .... anyway, after starting over and creating a working widget, now I struggle to get it right... I am looking to write some good tutorials based on my journey, I am not overly frustrated, just worried that I have to have this thing working by morning and am not looking forward to another 5am push...............

I am super appreciative of your help thus far. I am unfortunately a vetran to all development that != MVC, I have had success in the past with MVC 2 on crazy super simply apps...................

I would do about anything to have this done so I can get some sleep... I have reached out to you in a private thread. -James