You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
342 lines
15 KiB
Dart
342 lines
15 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mohem_flutter_app/api/vacation_rule_api_client.dart';
|
|
import 'package:mohem_flutter_app/classes/utils.dart';
|
|
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
|
|
import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
|
|
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
|
|
import 'package:mohem_flutter_app/models/vacation_rule/get_item_type_notifications_list_model.dart';
|
|
import 'package:mohem_flutter_app/models/vacation_rule/get_notification_reassign_mode_list_model.dart';
|
|
import 'package:mohem_flutter_app/models/vacation_rule/respond_attributes_list_model.dart';
|
|
import 'package:mohem_flutter_app/models/vacation_rule/vr_item_types_list_model.dart';
|
|
import 'package:mohem_flutter_app/models/vacation_rule/wf_look_up_list_model.dart';
|
|
import 'package:mohem_flutter_app/models/worklist/replacement_list_model.dart';
|
|
import 'package:mohem_flutter_app/widgets/app_bar_widget.dart';
|
|
import 'package:mohem_flutter_app/widgets/bottom_sheet.dart';
|
|
import 'package:mohem_flutter_app/widgets/bottom_sheets/search_employee_bottom_sheet.dart';
|
|
import 'package:mohem_flutter_app/widgets/button/default_button.dart';
|
|
import 'package:mohem_flutter_app/widgets/dynamic_forms/dynamic_textfield_widget.dart';
|
|
import 'package:mohem_flutter_app/widgets/item_detail_view_widget.dart';
|
|
|
|
class AddVacationRuleScreen extends StatefulWidget {
|
|
AddVacationRuleScreen({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
_AddVacationRuleScreenState createState() {
|
|
return _AddVacationRuleScreenState();
|
|
}
|
|
}
|
|
|
|
class _AddVacationRuleScreenState extends State<AddVacationRuleScreen> {
|
|
List<VrItemTypesList>? vrItemTypesList;
|
|
VrItemTypesList? selectedItemType;
|
|
|
|
List<GetItemTypeNotificationsList>? itemTypeNotificationsList;
|
|
GetItemTypeNotificationsList? selectedItemTypeNotification;
|
|
|
|
List<GetNotificationReassignModeList>? notificationReassignModeList;
|
|
GetNotificationReassignModeList? notificationReassignMode;
|
|
|
|
List<RespondAttributesList>? respondAttributesList;
|
|
List<WFLookUpList>? wfLookupList;
|
|
|
|
ReplacementList? selectedReplacementEmployee;
|
|
|
|
int currentStage = 0;
|
|
|
|
DateTime startTime = DateTime.now();
|
|
DateTime? endTime;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
getVacationRulesList();
|
|
}
|
|
|
|
void getVacationRulesList() async {
|
|
try {
|
|
Utils.showLoading(context);
|
|
vrItemTypesList = await VacationRuleApiClient().getVrItemTypes();
|
|
Utils.hideLoading(context);
|
|
currentStage = 1;
|
|
setState(() {});
|
|
} catch (ex) {
|
|
Utils.hideLoading(context);
|
|
Utils.handleException(ex, context, null);
|
|
}
|
|
}
|
|
|
|
void getItemTypeNotificationsList() async {
|
|
try {
|
|
Utils.showLoading(context);
|
|
itemTypeNotificationsList = await VacationRuleApiClient().getItemTypeNotifications(selectedItemType!.iTEMTYPE!);
|
|
itemTypeNotificationsList!.insert(0, GetItemTypeNotificationsList(nOTIFICATIONDISPLAYNAME: "All", nOTIFICATIONNAME: "*", fYIFLAG: "N"));
|
|
Utils.hideLoading(context);
|
|
currentStage = 2;
|
|
setState(() {});
|
|
} catch (ex) {
|
|
Utils.hideLoading(context);
|
|
Utils.handleException(ex, context, null);
|
|
}
|
|
}
|
|
|
|
void callCombineApis() async {
|
|
try {
|
|
Utils.showLoading(context);
|
|
List results = await Future.wait([
|
|
VacationRuleApiClient().getNotificationReassignMode(),
|
|
VacationRuleApiClient().getRespondAttributes(selectedItemType!.iTEMTYPE!, selectedItemTypeNotification!.nOTIFICATIONNAME!),
|
|
// VacationRuleApiClient().getWfLookup(P_LOOKUP_TYPE),
|
|
]);
|
|
notificationReassignModeList = results[0];
|
|
if (selectedItemType!.iTEMTYPE != "*") {
|
|
notificationReassignModeList!.add(
|
|
GetNotificationReassignModeList(
|
|
rADIOBUTTONLABEL: "Deliver notifications to me regardless of any general rules",
|
|
rADIOBUTTONACTION: "deliver_notification",
|
|
rADIOBUTTONSEQ: 1,
|
|
),
|
|
);
|
|
}
|
|
if (selectedItemTypeNotification!.fYIFLAG == "Y") {
|
|
notificationReassignModeList!.add(
|
|
GetNotificationReassignModeList(
|
|
rADIOBUTTONLABEL: "Close",
|
|
rADIOBUTTONACTION: "close",
|
|
rADIOBUTTONSEQ: 1,
|
|
),
|
|
);
|
|
}
|
|
respondAttributesList = results[1];
|
|
// wfLookupList = results[2];
|
|
Utils.hideLoading(context);
|
|
currentStage = 3;
|
|
setState(() {});
|
|
} catch (ex) {
|
|
Utils.hideLoading(context);
|
|
Utils.handleException(ex, context, null);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
appBar: AppBarWidget(
|
|
context,
|
|
title: LocaleKeys.vacationRule.tr(), // todo @Sikander change title to 'Vacation Type'
|
|
),
|
|
body: vrItemTypesList == null
|
|
? const SizedBox()
|
|
: (vrItemTypesList!.isEmpty
|
|
? Utils.getNoDataWidget(context)
|
|
: Column(
|
|
children: [
|
|
ListView(
|
|
padding: const EdgeInsets.all(21),
|
|
physics: const BouncingScrollPhysics(),
|
|
children: [
|
|
if (vrItemTypesList!.isNotEmpty)
|
|
PopupMenuButton(
|
|
child: DynamicTextFieldWidget(
|
|
LocaleKeys.itemType.tr(),
|
|
selectedItemType == null ? "Select Type" : selectedItemType!.iTEMTYPEDISPLAYNAME!,
|
|
isEnable: false,
|
|
isPopup: true,
|
|
).paddingOnly(bottom: 12),
|
|
itemBuilder: (_) => <PopupMenuItem<int>>[
|
|
for (int i = 0; i < vrItemTypesList!.length; i++) PopupMenuItem<int>(value: i, child: Text(vrItemTypesList![i].iTEMTYPEDISPLAYNAME!)),
|
|
],
|
|
onSelected: (int popupIndex) {
|
|
if (selectedItemType == vrItemTypesList![popupIndex]) {
|
|
return;
|
|
}
|
|
selectedItemType = vrItemTypesList![popupIndex];
|
|
setState(() {});
|
|
if (selectedItemType!.iTEMTYPE == "*") {
|
|
selectedItemTypeNotification = GetItemTypeNotificationsList(nOTIFICATIONDISPLAYNAME: "All", nOTIFICATIONNAME: "*", fYIFLAG: "N");
|
|
itemTypeNotificationsList = null;
|
|
notificationReassignMode = null;
|
|
callCombineApis();
|
|
} else {
|
|
selectedItemTypeNotification = null;
|
|
notificationReassignMode = null;
|
|
getItemTypeNotificationsList();
|
|
}
|
|
}).objectContainerView(title: "Apply for Vacation Rule\nStep 1", note: "*If All is selected, you will skip to step 3"),
|
|
if ((itemTypeNotificationsList ?? []).isNotEmpty) ...[
|
|
12.height,
|
|
PopupMenuButton(
|
|
child: DynamicTextFieldWidget(
|
|
"Notification",
|
|
selectedItemTypeNotification == null ? "Select Notification" : selectedItemTypeNotification!.nOTIFICATIONDISPLAYNAME!,
|
|
isEnable: false,
|
|
isPopup: true,
|
|
).paddingOnly(bottom: 12),
|
|
itemBuilder: (_) => <PopupMenuItem<int>>[
|
|
for (int i = 0; i < itemTypeNotificationsList!.length; i++) PopupMenuItem<int>(value: i, child: Text(itemTypeNotificationsList![i].nOTIFICATIONDISPLAYNAME!)),
|
|
],
|
|
onSelected: (int popupIndex) {
|
|
if (selectedItemTypeNotification == itemTypeNotificationsList![popupIndex]) {
|
|
return;
|
|
}
|
|
selectedItemTypeNotification = itemTypeNotificationsList![popupIndex];
|
|
notificationReassignMode = null;
|
|
setState(() {});
|
|
callCombineApis();
|
|
}).objectContainerView(title: "Step 2")
|
|
],
|
|
if (selectedItemType != null && selectedItemTypeNotification != null && currentStage == 3) ...[
|
|
12.height,
|
|
Column(
|
|
children: [
|
|
ItemDetailView(LocaleKeys.itemType.tr(), selectedItemType!.iTEMTYPEDISPLAYNAME!),
|
|
ItemDetailView("Notification", selectedItemTypeNotification!.nOTIFICATIONDISPLAYNAME!),
|
|
12.height,
|
|
DynamicTextFieldWidget(
|
|
"Start Date",
|
|
formattedDate(startTime),
|
|
suffixIconData: Icons.calendar_today,
|
|
isEnable: false,
|
|
onTap: () async {
|
|
var start = await _selectDateTime(context, startTime);
|
|
if (start != startTime) {
|
|
startTime = start;
|
|
setState(() {});
|
|
}
|
|
},
|
|
),
|
|
12.height,
|
|
DynamicTextFieldWidget(
|
|
"End Date",
|
|
formattedDate(endTime),
|
|
suffixIconData: Icons.calendar_today,
|
|
isEnable: false,
|
|
onTap: () async {
|
|
var end = await _selectDateTime(context, endTime ?? startTime);
|
|
if (end != endTime) {
|
|
endTime = end;
|
|
setState(() {});
|
|
}
|
|
},
|
|
),
|
|
12.height,
|
|
DynamicTextFieldWidget(
|
|
"Message",
|
|
"Write a message",
|
|
lines: 2,
|
|
onChange: (message) {},
|
|
// isEnable: false,
|
|
// isPopup: true,
|
|
).paddingOnly(bottom: 12),
|
|
PopupMenuButton(
|
|
child: DynamicTextFieldWidget(
|
|
"Notification Reassign",
|
|
notificationReassignMode == null ? "Select Notification" : notificationReassignMode!.rADIOBUTTONLABEL ?? "",
|
|
isEnable: false,
|
|
isPopup: true,
|
|
).paddingOnly(bottom: 12),
|
|
itemBuilder: (_) => <PopupMenuItem<int>>[
|
|
for (int i = 0; i < notificationReassignModeList!.length; i++) PopupMenuItem<int>(value: i, child: Text(notificationReassignModeList![i].rADIOBUTTONLABEL!)),
|
|
],
|
|
onSelected: (int popupIndex) {
|
|
if (notificationReassignMode == notificationReassignModeList![popupIndex]) {
|
|
return;
|
|
}
|
|
notificationReassignMode = notificationReassignModeList![popupIndex];
|
|
setState(() {});
|
|
}),
|
|
DynamicTextFieldWidget(
|
|
"Select Employee",
|
|
selectedReplacementEmployee == null ? "Search employee for replacement" : selectedReplacementEmployee!.employeeDisplayName ?? "",
|
|
isEnable: false,
|
|
onTap: () {
|
|
showMyBottomSheet(
|
|
context,
|
|
child: SearchEmployeeBottomSheet(
|
|
title: "Search for Employee",
|
|
apiMode: "DELEGATE",
|
|
onSelectEmployee: (_selectedEmployee) {
|
|
// Navigator.pop(context);
|
|
selectedReplacementEmployee = _selectedEmployee;
|
|
setState(() {});
|
|
},
|
|
),
|
|
);
|
|
},
|
|
).paddingOnly(bottom: 12),
|
|
],
|
|
).objectContainerView(title: "Step 3")
|
|
]
|
|
],
|
|
).expanded,
|
|
DefaultButton(
|
|
LocaleKeys.apply.tr(),
|
|
currentStage != 3
|
|
? null
|
|
: () {
|
|
if (currentStage == 1) {
|
|
getItemTypeNotificationsList();
|
|
} else if (currentStage == 2) {
|
|
callCombineApis();
|
|
}
|
|
},
|
|
).insideContainer,
|
|
],
|
|
)),
|
|
);
|
|
}
|
|
|
|
Future<DateTime> _selectDateTime(BuildContext context, DateTime _time) async {
|
|
DateTime time = _time;
|
|
if (Platform.isIOS) {
|
|
await showCupertinoModalPopup(
|
|
context: context,
|
|
builder: (cxt) => Container(
|
|
height: 250,
|
|
color: Colors.white,
|
|
child: CupertinoDatePicker(
|
|
backgroundColor: Colors.white,
|
|
mode: CupertinoDatePickerMode.dateAndTime,
|
|
onDateTimeChanged: (value) {
|
|
if (value != _time) {
|
|
time = value;
|
|
}
|
|
},
|
|
initialDateTime: _time,
|
|
),
|
|
),
|
|
);
|
|
} else {
|
|
final DateTime? picked = await showDatePicker(context: context, initialDate: _time, initialEntryMode: DatePickerEntryMode.calendarOnly, firstDate: DateTime(2015, 8), lastDate: DateTime(2101));
|
|
final TimeOfDay? timePicked = await showTimePicker(
|
|
context: context,
|
|
initialTime: TimeOfDay.fromDateTime(picked!),
|
|
);
|
|
if (picked != _time || timePicked != TimeOfDay.fromDateTime(picked)) {
|
|
time = picked;
|
|
time = time.add(
|
|
Duration(
|
|
hours: timePicked!.hour,
|
|
minutes: timePicked.minute,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
return time;
|
|
}
|
|
|
|
String formattedDate(DateTime? _time) {
|
|
if (_time == null) return "Select date and time";
|
|
return DateFormat("MM/dd/yyyy hh:mm:ss a").format(_time);
|
|
}
|
|
}
|