Ejemplo n.º 1
0
		private void _parseElement(JsonObject json, Section section, JsonValue data){
			string type = "Unknown";
			try {
				type = json["type"];
				if (type=="HiddenElement"){
					var name = json.s("id");
					
					_controller.SetValue(name, data==null? json.s("value") : data.CleanString());	
				} else {
					string id = (json.ContainsKey("id") ? json["id"] : null);
					var newElement = _parseFunctions[type](json, _controller, data);
					if (newElement!=null) {
						newElement.ID = id;
						_elements.Add(newElement);
						section.Add(newElement);
					}
				}
			} catch (Exception e){
				Console.WriteLine("Problem parsing element. Element was skipped. Type: "+type+" = " + e.ToString());
			}
		}
		private void _configureDialog(JsonValue json, JsonObject valuesJson){
			if (json.ContainsKey("grouped")) {
				Style = bool.Parse(json["grouped"].ToString()) ? UITableViewStyle.Grouped : UITableViewStyle.Plain;
			}
			if (json.ContainsKey("title"))
				Title = json["title"];
			
			if (json.ContainsKey("dataroot")) 
				DataRootName = json["dataroot"];
			
			if (json.ContainsKey("rightbaritem")){
				var item = (JsonObject)json["rightbaritem"];
				string datavalue = null, id = null;
				id = item.s("id");
				if (valuesJson!=null && !string.IsNullOrEmpty(id)){
					datavalue = valuesJson.s(id);
				}
					
				if (item.ContainsKey("action")) {
						rightBarItem = item.ContainsKey("url") ? 
							new SubmitElement(item.s("caption"), datavalue ?? item.s("url"), null, null) :
							new ActionElement(item.s("caption"), datavalue ?? item.s("action"), null);
						rightBarItem.ID = id;
				}	
				if (item.ContainsKey("image")){
					NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIImage.FromBundle(item.s("image")), UIBarButtonItemStyle.Plain, (object o, EventArgs a)=>{
						InvokeAction(this.rightBarItem);
					});
				} else {
					NavigationItem.RightBarButtonItem = new UIBarButtonItem(item.s("caption"), UIBarButtonItemStyle.Plain, (object o, EventArgs a)=>{
					InvokeAction(this.rightBarItem);
				});
				}
			}
			if (json.ContainsKey("leftbaritem")){
				var item = (JsonObject)json["leftbaritem"];
				if (item.ContainsKey("action")) {
						leftBarItem = item.ContainsKey("url") ? 
							new SubmitElement(item.s("caption"), item.s("url"), null, null) :
							new ActionElement(item.s("caption"), item.s("action"), null);
						leftBarItem.ID = item.s("id");
				}	
				NavigationItem.LeftBarButtonItem = new UIBarButtonItem(item.s("caption"), UIBarButtonItemStyle.Plain, (object o, EventArgs a)=>{
					InvokeAction(this.leftBarItem);
				});
			}
			
		}