private void Store_LoadComplete(object sender, EventArgs e) { if (this.IsDynamic) { return; } if (this.Page == null) { return; } string _ea = this.Page.Request["__EVENTARGUMENT"]; if (_ea.IsNotEmpty()) { string _et = this.Page.Request["__EVENTTARGET"]; if (_et == this.UniqueID) { RaiseAjaxPostBackEvent(_ea); } return; } if (this.DirectConfig == null) { return; } JToken eventArgumentToken = this.DirectConfig.SelectToken("config.__EVENTARGUMENT", false); if (eventArgumentToken == null) { throw new InvalidOperationException( "Incorrect submit config - the '__EVENTARGUMENT' parameter is absent"); } JToken eventTargetToken = this.DirectConfig.SelectToken("config.__EVENTTARGET", false); if (eventTargetToken == null) { throw new InvalidOperationException( "Incorrect submit config - the '__EVENTTARGET' parameter is absent"); } string id = JSON.ToString(eventTargetToken); if (id == this.UniqueID) { RaiseAjaxPostBackEvent(JSON.ToString(eventArgumentToken)); } }
/// <summary> /// /// </summary> /// <param name="token"></param> /// <returns></returns> public static string ToString(JToken token) { switch (token.Type) { case JTokenType.Property: return(JSON.ToString(((JProperty)token).Value)); case JTokenType.String: return((string)token); } return(token.ToString(Formatting.None)); }
public void RaiseAjaxPostBackEvent(string eventArgument, ParameterCollection extraParams) { bool success = true; string msg = null; Response response = new Response(); try { if (eventArgument.IsEmpty()) { throw new ArgumentNullException("eventArgument"); } string data = null; if (this.DirectConfig != null) { JToken serviceToken = this.DirectConfig.SelectToken("config.serviceParams", false); if (serviceToken != null) { data = JSON.ToString(serviceToken); } } switch (eventArgument) { case "submit": SubmitEventArgs se = new SubmitEventArgs(extraParams, JSON.Deserialize <SubmittedNode>(data, new CamelCasePropertyNamesContractResolver())); this.OnSubmit(se); break; case "raEdit": RemoteEditEventArgs rr = new RemoteEditEventArgs(data, extraParams); this.OnRemoteEdit(rr); success = rr.Accept; msg = rr.RefusalMessage; break; case "raRemove": RemoteRemoveEventArgs rrm = new RemoteRemoveEventArgs(data, extraParams); this.OnRemoteRemove(rrm); success = rrm.Accept; msg = rrm.RefusalMessage; break; case "raInsert": case "raAppend": RemoteAppendEventArgs ra = new RemoteAppendEventArgs(eventArgument == "raInsert", data, extraParams); this.OnRemoteAppend(ra); success = ra.Accept; msg = ra.RefusalMessage; break; case "raMove": RemoteMoveEventArgs rm = new RemoteMoveEventArgs(data, extraParams); this.OnRemoteMove(rm); success = rm.Accept; msg = rm.RefusalMessage; break; } } catch (Exception ex) { success = false; msg = this.IsDebugging ? ex.ToString() : ex.Message; if (this.ResourceManager.RethrowAjaxExceptions) { throw; } } response.Success = success; response.Message = msg; ResourceManager.ServiceResponse = response; }
private void RaiseAjaxPostBackEvent(string eventArgument) { try { if (eventArgument.IsEmpty()) { throw new ArgumentNullException("eventArgument"); } string data = null; JToken parametersToken = null; if (this.DirectConfig != null) { parametersToken = this.DirectConfig.SelectToken("config.extraParams", false); JToken serviceToken = this.DirectConfig.SelectToken("config.serviceParams", false); if (serviceToken != null) { data = JSON.ToString(serviceToken); } } string action = eventArgument; BeforeDirectEventArgs e = new BeforeDirectEventArgs(action, data, parametersToken); this.OnAjaxPostBack(e); if (this.AutoDecode && data.IsNotEmpty()) { data = HttpUtility.HtmlDecode(data); } switch (action) { case "create": case "destroy": case "update": case "batch": if (data == null) { throw new InvalidOperationException("No data in request"); } this.DoSaving(action, data, parametersToken); break; case "read": StoreReadDataEventArgs refreshArgs = new StoreReadDataEventArgs(parametersToken); this.OnReadData(refreshArgs); PageProxy dsp = this.Proxy.Primary as PageProxy; if (dsp != null) { if (refreshArgs.Total > -1) { dsp.Total = refreshArgs.Total; } } break; case "submit": if (data == null) { throw new InvalidOperationException("No data in request"); } StoreSubmitDataEventArgs args = new StoreSubmitDataEventArgs(data, parametersToken); this.OnSubmitData(args); break; } } catch (Exception ex) { success = false; msg = this.IsDebugging ? ex.ToString() : ex.Message; if (this.ResourceManager.RethrowAjaxExceptions) { throw; } } AfterDirectEventArgs eAjaxPostBackResult = new AfterDirectEventArgs(new Response(success, msg)); this.OnAjaxPostBackResult(eAjaxPostBackResult); StoreResponseData response = new StoreResponseData(); if (eAjaxPostBackResult.Response.Success) { switch (eventArgument) { case "read": if (this.RequiresDataBinding) { this.DataBind(); } response.Data = this.GetAjaxDataJson(); PageProxy dsp = this.Proxy.Primary as PageProxy; response.Total = dsp != null ? dsp.Total : -1; break; case "create": case "destroy": case "update": response.Data = JSON.Serialize(this.responseRecords); break; } } eAjaxPostBackResult.Response.Data = response.ToString(); ResourceManager.ServiceResponse = eAjaxPostBackResult.Response; }