When creating views in Monotouch Dialog, one possible way is to create .cs files which hold the view information like so:
[Caption("Create user")]
[Alignment(UITextAlignment.Center)]
public RegistrationSchema CreateAccount;
But say I needed to have button added dynamically, like so:
//This is what I'd like to do, but there doesn't seem to be any support for this
_newUserSection = new Section("Create user) {
new RegistrationSchema()
};
Any ideas?
Edit My RegistrationSchema.cs file
public class RegistrationSchema
{
[Section("Fill out the form")]
[Caption("E-mail")]
[Entry(KeyboardType=UIKeyboardType.EmailAddress)]
public string Email;
//more stuff here
}
// Create a new section
var section = new Section("A section");
// Create a new element
var elem = new StringElement("String Element")
// Add element to section
section.Add(elem);
// Add section to root.
Root.Add(section);
// Refresh
Root.ReloadData();
All well documented here https://github.com/migueldeicaza/MonoTouch.Dialog and in the Xamarin tutorials, like there http://blog.xamarin.com/2012/02/10/easily-create-ios-user-interfaces-with-monotouch-dialog/
To push a new controller, use a RootElement:
var newRoot = RootElement("Another root", new ThisWillBePushedController());
root.Add(newRoot);
Tapping the newRoot will push the ThisWillBePushedController().
Note that you'll have to override MonoTouch.DialogViewController and call the base c'tor passing TRUE for the last argument "pushing" if you're using a UINavigationController.
Related
I have a custom field in Orchard, I want it to have its own admin view to set the fields default value so that when it is used with other parts - it will always use this default display value.
I have the part, and the admin menu, currently the admin menu goes to the fields settings controller, but how do I create the fields shape for display?
I imagine something like this, but can't figure out what is the correct way to create the fields editor shape:
[Admin]
public class FieldAdminController : Controller
{
public ActionResult TimezoneSettings()
{
// var timezoneShape = Shape.Create("?");
// var model = new TimezoneViewModel(timezoneShape);
// return View(model);
// Or:
// TimezonePart part = Services.ContentManager.New<ITimezoneField>("TimezoneField");
//var model = Services.ContentManager.BuildEditor(part);
// return View(model);
}
}
The field does already work (i.e. the driver is working) when you attach the field to a content part via the admin UI, but I will only be using it with other code created custom parts in my modules.
I'm trying to Weld my custom ContentPart SitesPart containing a ContentField of type TaxonomyField but it is not working for me. When i attach this part from UI it works perfectly fine and i see the TaxonomyField in edit mode as well as in display mode.
Following is the Activating method of my ContentHandler.
protected override void Activating(ActivatingContentContext context)
{
if (context.ContentType == "Page")
{
context.Builder.Weld<SitesPart>();
}
}
I tried to go deep into the Weld function and found out that it is not able to find correct typePartDefinition. It goes inside the condition if (typePartDefinition == null) which creates an empty typePartDefinition with no existing ContentFields etc.
// obtain the type definition for the part
var typePartDefinition = _definition.Parts.FirstOrDefault(p => p.PartDefinition.Name == partName);
if (typePartDefinition == null) {
// If the content item's type definition does not define the part; use an empty type definition.
typePartDefinition =
new ContentTypePartDefinition(
new ContentPartDefinition(partName),
new SettingsDictionary());
}
I would be highly thankful for any guidance.
Oh, you are totally right, the part is welded but if there are some content fields, they are not welded. The ContentItemBuilder try to retrieve the part definition through the content type definition on which we want to add the part. So, because it's not possible, a new content part is created but with an empty collection of ContentPartFieldDefinition...
I think that the ContentItemBuilder would need to inject in its constructor and use a ContentPartDefinition or more generally an IContentDefinitionManager... But, for a quick workaround I've tried the following that works
In ContentItemBuilder.cs, replace this
public ContentItemBuilder Weld<TPart>()...
With
public ContentItemBuilder Weld<TPart>(ContentPartDefinition contentPartDefinition = null)...
And this
new ContentPartDefinition(partName),
With
contentPartDefinition ?? new ContentPartDefinition(partName),
And in you part handler, inject an IContentDefinitionManager and use this
protected override void Activating(ActivatingContentContext context) {
if (context.ContentType == "TypeTest") {
var contentPartDefinition = _contentDefinitionManager.GetPartDefinition(typeof(FruitPart).Name);
context.Builder.Weld<FruitPart>(contentPartDefinition);
}
}
Best
To attach a content part to a content type on the fly, you can use this in your handler
Filters.Add(new ActivatingFilter<YourContentPart>("YourContentType"));
There are many examples in the source code
Best
I have created a View using module, now in controller of this view i need to fetch some specific content type and return to view. Please can some one eleborate with code sample.
You will need to inject the IContentManager services in your controller constructor (see dependency injection) , but since you will need to populate a new shape, you could inject IOrchardServices which will include a few common OrchardServices in one instance.
IOrchardServices services;
public MyController(IOrchardServices services){
this.services = services;
}
Then in your action (if you want to show it on the front end you will have to mark it as themed), do something like this:
[Themed]
public ActionResult MyAction(){
//Notice that you can filter the contentItems here, this is just a basic example
var myContentItems = services.ContentManager.Query().ForType("MyContentItem").List();
//You probably need to create a new shape for showing the ContentTypes
var shape = services.New.YourCustomShape(); //Notice that you must create a view that matches this name
shape.YourContentItems = myContentItems;
return new ShapeResult(this, shape);
}
And that's it.
UPDATE: As it turns out, i had a leftover this.model = new MasterModel(); in my subViews initialize() function.
I am trying to separate my huge view to smaller views and so I have created a "master" layout view that attaches to itself some subviews and passes it's model to them.
However, it seems that when my sub-view updates the model, these changes are not reflected on the "master" view's model.
Here's what I am trying to do:
var master = new MasterModel();
var masterView = new MasterView({model:master});
Inside of the masterView initialize() function I do this:
function: initialize() {
this.subView = new subView({model:this.model});
}
And the code that changes the model in subView is this:
function: setCurrency() {
this.model.set({ currency: this.$('.currency').val() });
}
Maybe I am doing something completely wrong here?
How many things have class "currency" are on your page?
I don't think this.$('.currency').val() means what you think it means. I think you're wanting something like $(this.el).find('.currency').val() (are you using 0.9.1? then you could shorten that to $el.find('.currency').val() ). What you have will always grab the first item on the page with class "currency". this.$ is just a convenience reference to what would normally be the global Zepto or jQuery object. Hence, my question.
Edit: awaiting response to clarification question.
Make your model global so instead of:
var master = new MasterModel();
use
window.master = new MasterModel();
and then pas this to your subViews
function: initialize() {
this.subView = new subView({model:window.master});
}
I'm trying to use:
var viewEngineResult = ViewEngines.Engines.FindView(ControllerContext, myViewName, null);
as part of a process to render the contents of a view to send nice formatted emails. I'm using it inside an Orchard Controller. I have used similar code outside of Orchard in an MVC project and it works fine.
However in Orchard running this code fails to find the view I'm looking for and returns a view engine result that has searched 0 locations.
viewEngineResult has the following values after it is called:
SearchedLocations: Count = 0,
View: null,
ViewEngine: null
Is there a reason this doesn't work in Orchard and is there a way to make it work?
This answer is based on the advise given me by Bertrand, but I wanted to bring it together with what I'd discovered.
To be able to use FindPartialView I needed to inject an instance of IViewEngineProvider into my controller.
I then used the following code to resolve and render a view:
private String RenderView(String viewName, object model)
{
var paths = new List<string>(); // This can just be an empty list and it still finds it.
var viewEngine = _viewEngineProvider.CreateModulesViewEngine(new CreateModulesViewEngineParams {VirtualPaths = paths});
var viewResult = viewEngine.FindPartialView(ControllerContext, viewName, false);
if (viewResult.View == null) {
throw new Exception("Couldn't find view " + viewName);
}
var viewData = new ViewDataDictionary {Model = model};
using (var sw = new StringWriter())
{
var viewContext = new ViewContext(ControllerContext, viewResult.View, viewData, TempData, sw);
viewResult.View.Render(viewContext, sw);
return sw.GetStringBuilder().ToString();
}
}
I think you'll want to take a close look at Orchard.Framework/Mvc/ViewEngines, in particular IViewEngineProvider and ThemeAwareViewEngine. There's a lot more going on when in Orchard, such as themes, multi-tenancy, and a richer environment in general that may be needed to make this work.
What's likely happening here is that the view engines don't have enough information to resolve a view and thus opt out of the chain. You might want to put a breakpoint into ThemeAwareViewEngine.FindView, and then inspect the private dependency fields of that class. I wouldn't be surprised if they were null, because getting to FindView through statics will probably not allow dependency injection to do its stuff properly.
Then again I'm just guessing.