localAction method

dynamic localAction(
  1. dynamic requestFirst,
  2. dynamic context
)

Implementation

localAction(requestFirst, context) {
  myLogAll('localAction $requestFirst');
  Map data;
  try {
    data = requestFirst[gData];
  } catch (e) {
    MapEntry me = requestFirst[gData];
    data = me.value;
  }
  if (data.containsKey(gFunction)) {}
  myLog('----   localAction data is $data');
  if (data[gLabel] != null && data[gLabel] == gConfirm) {
    if (data[gItem] != null) {
      Map item = data[gItem];
      var id = data[gId];
      var type = item[gType];
      String value = '';
      var dpid = getDPidfromItem(item);

      if (type == gDate || type == gDatetime || !isNull(dpid)) {
        if (type == gDate || type == gDatetime) {
          value =
              '${_dpList[gYear][_dpListDefaultIndex[gYear]]}-${_dpList[gMonth][_dpListDefaultIndex[gMonth]]}-${_dpList[gDay][_dpListDefaultIndex[gDay]]}';
          if (id == gAdvanceSearch) {
            id = item[gId];
            dynamic tableId = data[gName];
            value =
                '$value ${_dpList[gHour][_dpListDefaultIndex[gHour]]}:00:00';
            dynamic value1 =
                '${_dpList['${gYear}1'][_dpListDefaultIndex['${gYear}1']]}-${_dpList['${gMonth}1'][_dpListDefaultIndex['${gMonth}1']]}-${_dpList['${gDay}1'][_dpListDefaultIndex['${gDay}1']]} ${_dpList['${gHour}1'][_dpListDefaultIndex['${gHour}1']]}:59:59';
            dynamic entrytime0 = toUTCTime(value);
            dynamic entrytime1 = toUTCTime(value1);
            if (entrytime0 < entrytime1) {
              dynamic where =
                  '${item[gId]}>=$entrytime0 and ${item[gId]}<=$entrytime1';
              removeOverlay();

              setTableWhere({gTableID: tableId, gValue: where}, context);
              return;
            } else {
              return;
            }
          }
        } else if (type == gIcon) {
          var indexRow = getDPIndex(_dpListDefaultIndex[dpid], item);
          value = indexRow[gValue].toString();
          //value = getInt(value);
        } else {
          var indexRow = getDPIndex(_dpListDefaultIndex[dpid], item);
          if (indexRow is Map) {
            value = indexRow[gLabel];
          } else {
            value = indexRow;
          }
        }

        bool status = setItemAferDPClick(
            item, value, data[gTypeOwner], data[gName], id, context);

        if (status) {
          removeOverlay();
        }
      }
    }
  } else if (data[gLabel] != null &&
      data[gLabel] == gEdit &&
      data[gTableID] != null) {
    //var tableId = data[gTableID];
    //int index = data[gRow];
    showFormEdit(data, context);
    showTableForm(data, context, _defaultBackGroundColor);
  } else if (data[gLabel] != null &&
      data[gLabel] == gSave &&
      data[gTableID] != null) {
    saveTableModify(data, context);
  } else if (data[gLabel] != null &&
      data[gLabel] == gCancel &&
      data[gTableID] != null) {
    cancelTableModify(data, context);
  } else if (data[gLabel] != null &&
      data[gLabel] == gSaveall &&
      data[gTableID] != null) {
    saveTableModifyAll(data, context);
  } else if (data[gLabel] != null &&
      data[gLabel] == gAddnew &&
      data[gTableID] != null) {
    tableAddNew(data, context);
  } else if (data[gLabel] != null &&
      data[gLabel] == gAdvanceSearch &&
      data[gTableID] != null) {
    tableAddNew(data, context);
  } else if (data[gLabel] != null &&
      data[gLabel] == gPdf &&
      data[gTableID] != null) {
    toPdf(data, context);
  } else if (data[gLabel] != null &&
      data[gLabel] == gExcel &&
      data[gTableID] != null) {
    toExcel(data, context);
  } else if (data[gLabel] != null &&
      data[gLabel] == gDelete &&
      data[gTableID] != null) {
    var tableId = data[gTableID];
    Map rowData = data[gRow];
    var keyValue = getTableValueKey(tableId, rowData);
    data[gLabel] = gSureDelete;
    showAlertDialog(
        context, gAlert, "$gRemove [$keyValue], areyousure ?", requestFirst);
    //);

    return;
  } else if (data[gLabel] != null &&
      data[gLabel] == gSureDelete &&
      data[gTableID] != null) {
    deleteTableOne(data, context);
    /*int row = data[gRow];
    //popup confirm dialog
    //show delete confirm dialog, and send delete request.
    var dataDelete = {};
    dataDelete[gFormid] = data[gTableID];
    dataDelete[gId] = _tableList[data[gTableID]][gData][row][gId];
    sendRequestOne('formchange', [dataDelete], context);*/
  } else if (data[gLabel] != null &&
      data[gLabel] == gDetail &&
      data[gTableID] != null) {
    var tableId = data[gTableID];
    Map rowData = getMap(data[gRow]);
    var primaryValue = getTableValueKey(tableId, rowData);
    var transpass = '';
    if (data[gTranspass] != null) {
      transpass = data[gTranspass];
    }
    //{gAction: gProcess,gData:[{gLabel:"",gType:gTable,gActionid:"Zzyimage","colorIndex":0}],"token":"89345dd3-f653-48a3-b7c1-b2d4af8728c1","companyid":"smilesmart"}
    Map element = {
      gLabel:
          "$gDetail for ${getTableValueAttr(tableId, gLabel)} [ $primaryValue ]",
      gType: gTable,
      gActionid: getTableValueAttr(tableId, gDetail),
      gWhere: "$gParentid='${getTableValue(rowData, gId)}'",
      gColorIndex: 0,
      gTranspass: transpass
    };
    sendRequestOne(gProcess, [element], context);
    //show delete confirm dialog, and send delete request.
    //open detail
    //sendRequestOne('formchange', [dataDelete], context);
  } else if (data[gLabel] != null &&
      data[gLabel] == gRemove &&
      data[gTabIndex] != null &&
      data[gTabName] != null) {
    //remove tab
    deleteTabOne(data[gTabName], data[gTabIndex]);
  } else if (data[gLabel] != null &&
      data[gLabel] == gRefresh &&
      data[gTabIndex] != null &&
      data[gTabName] != null) {
    sendRequestOne(
        gProcess,
        [
          {
            gLabel: _tabList[data[gTabName]][gData][data[gTabIndex]][gLabel],
            gType: _tabList[data[gTabName]][gData][data[gTabIndex]][gType],
            gActionid: _tabList[data[gTabName]][gData][data[gTabIndex]]
                [gActionid],
            gWhere: _tabList[data[gTabName]][gData][data[gTabIndex]][gWhere],
            gColorIndex: 0
          }
        ],
        context);

    /*sendRequestOne(
              _param[gType], _param, _param[gContext] ?? context);*/
  } else if (data[gLabel] != null &&
      data[gLabel] == gTreeExpand &&
      data[gValue] != null &&
      data[gMove] != null) {
    //bool expanded = data[gMove];
    //dynamic key = data[gValue];
  } else if (data[gLabel] != null &&
      data[gLabel] == gTreeSelected &&
      data[gValue] != null) {
    if (data[gData] != null && data[gData][gType] != null) {
      if (data[gData][gType] == gTabletree) {
        dynamic tableid = data[gValue] ?? '';
        if (tableid != '') {
          //show table
          Map element = {
            gLabel: data[gTreeLabel],
            gType: gTable,
            gActionid: tableid,
            gWhere: "",
            gColorIndex: 0
          };
          sendRequestOne(gProcess, [element], context);
        }
      }
    }
  } else if (data[gLabel] != null &&
      data[gLabel] == gSearch &&
      data[gTableID] != null) {
    searchTable(data, context);
  } else if (!isNull(data[gLabel]) && data[gLabel] == gLogout) {
    logOff(context);
  } else if (!isNull(data[gAction1])) {
    businessFunc(data[gAction1], context, data);
  } else if (!isNull(data[gLabel]) &&
      data[gLabel] == gLog &&
      data[gTableID] != null) {
    var id = data[gRow][gId];
    var name = data[gTableID];
    var where = "dataid='$id' order by entrytime";
    getTableFromDB('${gZzylog}_$name', where, context);
  } else if (!isNull(data[gAction])) {
    myLog('-----------localAction  $data');
    //_instanceMirror.invoke(data[Action], [data, context]);
    invoke(data[Action], [data, context], context);
  } else if (!isNull(data[gActionid])) {
    myLog('-----------localAction1  $data');
    //_instanceMirror.invoke(data[gActionid], [data, context]);
    invoke(data[gActionid], [data, context], context);
  }
}