|
|
@@ -1,9 +1,12 @@
|
|
|
package com.usai.ratradefiling.tfeditor;
|
|
|
|
|
|
+import android.app.ProgressDialog;
|
|
|
import android.content.Context;
|
|
|
//import android.support.v7.app.AppCompatActivity;
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
+import android.view.MenuItem;
|
|
|
+import android.view.View;
|
|
|
|
|
|
//import com.usai.redant.CommonEditor.CommonEditorActivity;
|
|
|
//import com.usai.redant.redantmobile.R;
|
|
|
@@ -13,14 +16,17 @@ import com.usai.commoneditorlib.CommonEditorActivity;
|
|
|
import com.usai.commoneditorlib.EnumSlectOnlineActivity;
|
|
|
import com.usai.ratradefiling.R;
|
|
|
import com.usai.ratradefiling.dataprovider.RADataProvider;
|
|
|
+import com.usai.redant.rautils.utils.Network;
|
|
|
import com.usai.redant.rautils.utils.RAUtil;
|
|
|
|
|
|
+import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
import java.lang.reflect.ParameterizedType;
|
|
|
|
|
|
import static com.usai.ratradefiling.dataprovider.OnlineDataProvider.URL_CADEDATE;
|
|
|
import static com.usai.ratradefiling.dataprovider.OnlineDataProvider.URL_EDIT;
|
|
|
+import static com.usai.redant.rautils.utils.RAUtil.getJsonFromAsset;
|
|
|
|
|
|
public class TFEditorActivity extends CommonEditorActivity
|
|
|
{
|
|
|
@@ -52,13 +58,374 @@ public class TFEditorActivity extends CommonEditorActivity
|
|
|
return RADataProvider.request_editor(request_url, params);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item)
|
|
|
+ {
|
|
|
+
|
|
|
+ JSONObject jitem = injectMenu.optJSONObject(item.getItemId());
|
|
|
+
|
|
|
+ if(jitem==null)
|
|
|
+ {
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
+ }
|
|
|
+ String type = jitem.optString("type");
|
|
|
+
|
|
|
+// UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
|
|
+
|
|
|
+
|
|
|
+ if (lastEditText != null) {
|
|
|
+ endEditting();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject upparams = check_cancomit(false);
|
|
|
+
|
|
|
+
|
|
|
+ for(int i=0;i<injectMenu.length();i++)
|
|
|
+ {
|
|
|
+
|
|
|
+ JSONObject subitem = injectMenu.get(i);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// UIAlertAction *injectAction = [UIAlertAction actionWithTitle:NSLocalizedString(item[@"title"], nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+
|
|
|
+ if(subitem.optString("name","").equals("save"))
|
|
|
+ {
|
|
|
+ JSONObject params= subitem.optJSONObject("params");
|
|
|
+
|
|
|
+ RAUtil.mergeJson(upparams,params);
|
|
|
+
|
|
|
+ final ProgressDialog pd = RAUtil.waiting_alert(mCtx,"Saving","please wait");
|
|
|
+
|
|
|
+ new Thread(new Runnable()
|
|
|
+ {
|
|
|
+ @Override
|
|
|
+ public void run()
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject result_json = null;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject finalResult_json = result_json;
|
|
|
+ runOnUiThread(new Runnable()
|
|
|
+ {
|
|
|
+ @Override
|
|
|
+ public void run()
|
|
|
+ {
|
|
|
+
|
|
|
+ pd.dismiss();
|
|
|
+
|
|
|
+
|
|
|
+// pd.dismiss();
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ int result = finalResult_json.optInt("result");
|
|
|
+ if (result == 2)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (option != LoadDataOptionLoadMore)
|
|
|
+ {
|
|
|
+ mCadedate = new JSONObject();
|
|
|
+ }
|
|
|
+
|
|
|
+ int count = finalResult_json.optInt("count");
|
|
|
+ if (count >= limit)
|
|
|
+ {
|
|
|
+ hasmore = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ mListFooterView.setText("No more data");
|
|
|
+ mListFooterView.setVisibility(View.VISIBLE);
|
|
|
+ hasmore = false;
|
|
|
+
|
|
|
+ }
|
|
|
+ int ccount = mCadedate.optInt("count");
|
|
|
+ for (int ipr = 0; ipr < count; ipr++)
|
|
|
+ {
|
|
|
+
|
|
|
+ JSONObject item = finalResult_json.optJSONObject("val_" + ipr);
|
|
|
+
|
|
|
+
|
|
|
+ mCadedate.put("val_" + (ccount + ipr), item);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ mCadedate.put("count", ccount + count);
|
|
|
+ offset = ccount + count;
|
|
|
+
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ RAUtil.alertMessage(mCtx, "", finalResult_json.optString("err_msg"));
|
|
|
+ }
|
|
|
+ } catch (JSONException e)
|
|
|
+ {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [RADataProvider SaveEditor:upparams completionHandler:^(NSMutableDictionary *result) {
|
|
|
+ int ret=[result[@"result"] intValue];
|
|
|
+
|
|
|
+ if (ret==RESULT_TRUE)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ [RAUtils message_alert:@"Successful" title:@"Save" controller:self action_handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ [self.navigationController popViewControllerAnimated:YES];
|
|
|
+ [self prepareReturn:nil];
|
|
|
+ } completion:^{
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }];
|
|
|
+ // NSUser
|
|
|
+
|
|
|
+// [self.navigationController popViewControllerAnimated:true];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_LOGIN_FAILED object:nil];
|
|
|
+ // int a = RESULT_NET_NOTAVAILABLE;
|
|
|
+ NSString* message = nil;
|
|
|
+ switch (ret) {
|
|
|
+ case RESULT_NET_NOTAVAILABLE:
|
|
|
+ message = NSLocalizedString(@"net_not_available", nil);
|
|
|
+ break;
|
|
|
+ case RESULT_NET_ERROR:
|
|
|
+ message = NSLocalizedString(@"net_error", nil);
|
|
|
+ break;
|
|
|
+ case RESULT_FALSE:
|
|
|
+ message = NSLocalizedString(@"auth_error", nil);
|
|
|
+ break;
|
|
|
+ case RESULT_VER_LOW:
|
|
|
+ message = NSLocalizedString(@"ver_low", nil);
|
|
|
+ break;
|
|
|
+ case RESULT_FAILED_WITH_MESSAGE:
|
|
|
+ message = result[@"err_msg"];
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ message=[NSString stringWithFormat:@"Failed to login code %d",ret];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_error", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
|
|
|
+ UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ [alertVC addAction:action];
|
|
|
+
|
|
|
+ [self presentViewController:alertVC animated:YES completion:nil];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ }else
|
|
|
+ if([item[@"name"] isEqualToString:@"save&submit"])
|
|
|
+ {
|
|
|
+ JSONObject params= item[@"params"];
|
|
|
+ [upparams addEntriesFromDictionary:params];
|
|
|
+
|
|
|
+ [RADataProvider SaveEditor:upparams completionHandler:^(NSMutableDictionary *result) {
|
|
|
+ int ret=[result[@"result"] intValue];
|
|
|
+
|
|
|
+ if (ret==RESULT_TRUE)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ [RAUtils message_alert:@"Successful" title:@"Save" controller:self action_handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ [self.navigationController popViewControllerAnimated:YES];
|
|
|
+ [self prepareReturn:nil];
|
|
|
+
|
|
|
+ } completion:^{
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }];
|
|
|
+ // NSUser
|
|
|
+
|
|
|
+ // [self.navigationController popViewControllerAnimated:true];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_LOGIN_FAILED object:nil];
|
|
|
+ // int a = RESULT_NET_NOTAVAILABLE;
|
|
|
+ NSString* message = nil;
|
|
|
+ switch (ret) {
|
|
|
+ case RESULT_NET_NOTAVAILABLE:
|
|
|
+ message = NSLocalizedString(@"net_not_available", nil);
|
|
|
+ break;
|
|
|
+ case RESULT_NET_ERROR:
|
|
|
+ message = NSLocalizedString(@"net_error", nil);
|
|
|
+ break;
|
|
|
+ case RESULT_FALSE:
|
|
|
+ message = NSLocalizedString(@"auth_error", nil);
|
|
|
+ break;
|
|
|
+ case RESULT_VER_LOW:
|
|
|
+ message = NSLocalizedString(@"ver_low", nil);
|
|
|
+ break;
|
|
|
+ case RESULT_FAILED_WITH_MESSAGE:
|
|
|
+ message = result[@"err_msg"];
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ message=[NSString stringWithFormat:@"Failed to login code %d",ret];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_error", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
|
|
|
+ UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ [alertVC addAction:action];
|
|
|
+
|
|
|
+ [self presentViewController:alertVC animated:YES completion:nil];
|
|
|
+ }
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ if([item[@"name"] isEqualToString:@"delete"])
|
|
|
+ {
|
|
|
+ JSONObject params= item[@"params"];
|
|
|
+ [upparams addEntriesFromDictionary:params];
|
|
|
+
|
|
|
+ [RADataProvider SaveEditor:upparams completionHandler:^(NSMutableDictionary *result) {
|
|
|
+ int ret=[result[@"result"] intValue];
|
|
|
+
|
|
|
+ if (ret==RESULT_TRUE)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ [RAUtils message_alert:@"Successful" title:@"Delete" controller:self action_handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ [self.navigationController popViewControllerAnimated:YES];
|
|
|
+ [self prepareReturn:nil];
|
|
|
+ } completion:^{
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }];
|
|
|
+ // NSUser
|
|
|
+
|
|
|
+ // [self.navigationController popViewControllerAnimated:true];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_LOGIN_FAILED object:nil];
|
|
|
+ // int a = RESULT_NET_NOTAVAILABLE;
|
|
|
+ NSString* message = nil;
|
|
|
+ switch (ret) {
|
|
|
+ case RESULT_NET_NOTAVAILABLE:
|
|
|
+ message = NSLocalizedString(@"net_not_available", nil);
|
|
|
+ break;
|
|
|
+ case RESULT_NET_ERROR:
|
|
|
+ message = NSLocalizedString(@"net_error", nil);
|
|
|
+ break;
|
|
|
+ case RESULT_FALSE:
|
|
|
+ message = NSLocalizedString(@"auth_error", nil);
|
|
|
+ break;
|
|
|
+ case RESULT_VER_LOW:
|
|
|
+ message = NSLocalizedString(@"ver_low", nil);
|
|
|
+ break;
|
|
|
+ case RESULT_FAILED_WITH_MESSAGE:
|
|
|
+ message = result[@"err_msg"];
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ message=[NSString stringWithFormat:@"Failed to login code %d",ret];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_error", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
|
|
|
+ UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ [alertVC addAction:action];
|
|
|
+
|
|
|
+ [self presentViewController:alertVC animated:YES completion:nil];
|
|
|
+ }
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ else
|
|
|
+ if([item[@"name"] isEqualToString:@"save_party"])
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [alertVC addAction:injectAction];
|
|
|
+
|
|
|
+ }
|
|
|
+ UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ [alertVC addAction:cancelAction];
|
|
|
+
|
|
|
+ [self presentViewController:alertVC animated:YES completion:nil];
|
|
|
+
|
|
|
+
|
|
|
+//
|
|
|
+// if(type.toLowerCase().equals("quickview"))
|
|
|
+// {
|
|
|
+// String url = jitem.optString("url");
|
|
|
+// showQuickLook(url);
|
|
|
+// }
|
|
|
+// else if(type.toLowerCase().equals("editor"))
|
|
|
+// {
|
|
|
+//// throw new AssertionError("Editor not impl");
|
|
|
+//
|
|
|
+//
|
|
|
+// Bundle b=RAUtil.Json2Bundle(jitem.optJSONObject("params"));
|
|
|
+// Intent intent = TFEditorActivity.build(mContext,TFEditorActivity.class,null,URL_REMOTE,URL_EDIT,b);
|
|
|
+//
|
|
|
+// startActivity(intent);
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
+// return super.onOptionsItemSelected(item);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
protected void commonAction(String value, int groupIndex, int itemIndex, JSONObject item_json)
|
|
|
{
|
|
|
if(value.equals("editor"))
|
|
|
{
|
|
|
-// NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
|
|
|
+// JSONObject item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
|
|
|
boolean readonly = content_data_download.optBoolean("readonly");
|
|
|
|
|
|
int disable = item_json.optInt("disable");
|
|
|
@@ -122,7 +489,7 @@ public class TFEditorActivity extends CommonEditorActivity
|
|
|
// // enumvc.single_select =[[single_select lowercaseString] isEqualToString:@"true"];
|
|
|
//
|
|
|
// enumvc.from = indexPath;
|
|
|
-// enumvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
|
|
|
+// enumvc.returnValue = ^(JSONObject value,NSIndexPath* source){
|
|
|
//
|
|
|
//
|
|
|
// [self handle_action_return:value[@"val_0"] indexPath:indexPath action:ACTION_FILL_SECTION];
|