-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMasterViewController.cs
executable file
·422 lines (349 loc) · 14.5 KB
/
MasterViewController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
using System;
using System.Collections.Generic;
using UIKit;
using Foundation;
using MonoTouch.Dialog;
using Newtonsoft.Json;
using System.Drawing;
namespace DynaPad
{
public partial class MasterViewController : DialogViewController
{
public DetailViewController DetailViewController { get; set; }
public DialogViewController mvc { get; set; }
UILabel messageLabel;
LoadingOverlay loadingOverlay;
protected MasterViewController(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
Title = NSBundle.MainBundle.LocalizedString("Menu", "Form Sections");
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
{
//PreferredContentSize = new CGSize(320f, 600f);
ClearsSelectionOnViewWillAppear = false;
}
DetailViewController = (DetailViewController)((UINavigationController)SplitViewController.ViewControllers[1]).TopViewController;
DetailViewController.Style = UITableViewStyle.Plain;
// TODO pull to refresh: (problem scrolling with it..)
//DetailViewController.RefreshRequested += delegate
//{
// DetailViewController.ReloadComplete();
//};
var dds = new DynaPadService.DynaPadService();
var menu = dds.BuildDynaMenu("123");
var menuObj = JsonConvert.DeserializeObject<Menu>(dds.BuildDynaMenu("123"));
Menu myDynaMenu = JsonConvert.DeserializeObject<Menu>(dds.BuildDynaMenu("123"));
var rootMainMenu = new RootElement(myDynaMenu.MenuCaption);
var sectionMainMenu = new Section();
sectionMainMenu.HeaderView = null;
BuildMenu(myDynaMenu, sectionMainMenu);
rootMainMenu.Add(sectionMainMenu);
Root = rootMainMenu;
}
private RootElement BuildMenu(Menu myMenu, Section sectionMenu)
{
if (myMenu.MenuItems == null) return null;
foreach (MenuItem mItem in myMenu.MenuItems)
{
var rootMenu = new DynaFormRootElement(mItem.MenuItemCaption);
rootMenu.Enabled = true;
rootMenu.FormID = mItem.MenuItemValue;
rootMenu.FormName = mItem.MenuItemCaption;
rootMenu.MenuAction = mItem.MenuItemAction;
rootMenu.MenuValue = mItem.MenuItemValue;
rootMenu.PatientID = mItem.PatientId;
rootMenu.DoctorID = mItem.DoctorId;
rootMenu.LocationID = mItem.LocationId;
rootMenu.ApptID = mItem.ApptId;
rootMenu.IsDoctorForm = mItem.MenuItemAction == "GetDoctorForm";
switch (mItem.MenuItemAction)
{
case "GetPatientForm":
case "GetDoctorForm":
rootMenu.createOnSelected = GetFormService;
break;
case "GetAppt":
rootMenu.createOnSelected = GetApptService;
break;
case "GetReport":
sectionMenu.Add(new StringElement(mItem.MenuItemCaption, delegate { LoadReportView("Report", mItem.MenuItemValue); }));
//rootMenu.createOnSelected = GetReportService;
//Section sectionReport = new Section();
//sectionReport.Add(new StringElement(rootMenu.MenuValue, delegate { LoadReportView("Report", rootMenu.MenuValue); }));
//rootMenu.Add(sectionReport);
break;
}
if (mItem.MenuItemAction != "GetReport")
{
sectionMenu.Add(rootMenu);
}
if (mItem.Menus == null) return null;
foreach (Menu mRoot in mItem.Menus)
{
var newSection = new Section();
BuildMenu(mRoot, newSection);
rootMenu.Add(newSection);
}
}
return null;
}
public UIViewController GetApptService(RootElement rElement)
{
if (DetailViewController.QuestionsView != null)
{
DetailViewController.Title = "";
DetailViewController.QuestionsView.Clear();
}
var dfElemet = (DynaFormRootElement)rElement;
SelectedAppointment.ApptFormId = dfElemet.FormID;
SelectedAppointment.ApptFormName = dfElemet.FormName;
SelectedAppointment.ApptPatientId = dfElemet.PatientID;
SelectedAppointment.ApptDoctorId = dfElemet.DoctorID;
SelectedAppointment.ApptLocationId = dfElemet.LocationID;
SelectedAppointment.ApptId = dfElemet.ApptID;
return new DialogViewController(rElement, true);
}
public UIViewController GetReportService(RootElement rElement)
{
if (DetailViewController.QuestionsView != null)
{
DetailViewController.Title = "";
DetailViewController.QuestionsView.Clear();
}
var dfElemet = (DynaFormRootElement)rElement;
//var ShortForm = SelectedAppointment.ApptShortForms.Find((QShortForm obj) => obj.FormId == dfElemet.MenuValue);
var dds = new DynaPadService.DynaPadService();
string origJson = dds.GetShortForms(dfElemet.FormID, dfElemet.DoctorID, false);
JsonHandler.OriginalFormJsonString = origJson;
var rootReports = new RootElement(dfElemet.FormName);
var sectionReports = new Section();
foreach (Report esf in SelectedAppointment.ApptReports)
{
sectionReports.Add(new StringElement(esf.ReportName, delegate { LoadSectionView(esf.ReportId, "Report", null, false); }));
}
rootReports.Add(sectionReports);
var formDVC = new DialogViewController(rootReports, true);
return formDVC;
}
public UIViewController GetFormService(RootElement rElement)
{
//if (DetailViewController.QuestionsView != null)
//{
// DetailViewController.Title = "";
// DetailViewController.QuestionsView.Clear();
//}
var bounds = UIScreen.MainScreen.Bounds;
// show the loading overlay on the UI thread using the correct orientation sizing
loadingOverlay = new LoadingOverlay(bounds);
mvc = (DialogViewController)((UINavigationController)SplitViewController.ViewControllers[0]).TopViewController;
mvc.Add(loadingOverlay);
var dds = new DynaPadService.DynaPadService();
var dfElemet = (DynaFormRootElement)rElement;
string origJson = dds.GetFormQuestions(dfElemet.FormID, dfElemet.PatientID, dfElemet.ApptID, dfElemet.IsDoctorForm);
JsonHandler.OriginalFormJsonString = origJson;
SelectedAppointment.SelectedQForm = JsonConvert.DeserializeObject<QForm>(origJson);
var rootFormSections = new RootElement(SelectedAppointment.SelectedQForm.FormName);
var sectionFormSections = new Section();
bool IsDoctorForm = dfElemet.IsDoctorForm;
if (IsDoctorForm)
{
/*
* TODO: make presets password protected (maybe not, since for doctors only?)! (maybe component: Passcode)
*/
var FormPresetNames = dds.GetAnswerPresets(SelectedAppointment.ApptFormId, null, SelectedAppointment.ApptPatientId, true, SelectedAppointment.ApptLocationId);
var formPresetSection = new DynaSection("Form Preset Answers");
formPresetSection.Enabled = true;
var formPresetGroup = new RadioGroup("FormPresetAnswers", SelectedAppointment.SelectedQForm.FormSelectedTemplateId);
var formPresetsRoot = new DynaRootElement("Preset Answers", formPresetGroup);
formPresetsRoot.IsPreset = true;
foreach(string[] arrPreset in FormPresetNames)
{
var radioPreset = new MyRadioElement(arrPreset[1], "FormPresetAnswers");
radioPreset.OnSelected += delegate (object sender, EventArgs e)
{
string presetJson = arrPreset[2];
JsonHandler.OriginalFormJsonString = presetJson;
SelectedAppointment.SelectedQForm = JsonConvert.DeserializeObject<QForm>(presetJson);
LoadSectionView(SelectedAppointment.SelectedQForm.FormSections[0].SectionId, SelectedAppointment.SelectedQForm.FormSections[0].SectionName, SelectedAppointment.SelectedQForm.FormSections[0], IsDoctorForm);
};
formPresetSection.Add(radioPreset);
}
var btnNewFormPreset = new GlassButton(new RectangleF(0, 0, (float)View.Frame.Width, 50));
btnNewFormPreset.Font = UIFont.BoldSystemFontOfSize(17);
btnNewFormPreset.SetTitleColor(UIColor.Black, UIControlState.Normal);
btnNewFormPreset.NormalColor = UIColor.FromRGB(224, 238, 240);
btnNewFormPreset.SetTitle("Save New Form Preset", UIControlState.Normal);
btnNewFormPreset.TouchUpInside += (sender, e) =>
{
/*
* TODO: popup to enter preset name (DONE?)
*/
//Create Alert
var SavePresetPrompt = UIAlertController.Create("New Form Preset", "Necesito name", UIAlertControllerStyle.Alert);
SavePresetPrompt.AddTextField((field) =>
{
field.Placeholder = "Preset Name";
});
//Add Actions
SavePresetPrompt.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, action => SavePreset(SavePresetPrompt.TextFields[0].Text)));
SavePresetPrompt.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));
//Present Alert
PresentViewController(SavePresetPrompt, true, null);
};
formPresetSection.Add(btnNewFormPreset);
formPresetsRoot.Add(formPresetSection);
formPresetsRoot.Enabled = true;
sectionFormSections.Add(formPresetsRoot);
}
foreach (FormSection fSection in SelectedAppointment.SelectedQForm.FormSections)
{
sectionFormSections.Add(new StringElement(fSection.SectionName, delegate { LoadSectionView(fSection.SectionId, fSection.SectionName, fSection, IsDoctorForm); }));
}
sectionFormSections.Add(new StringElement("Finalize", delegate { LoadSectionView("Finalize", "Finalize", null, IsDoctorForm); }));
rootFormSections.Add(sectionFormSections);
var formDVC = new DialogViewController(rootFormSections, true);
// TODO pull to refresh: (problamatic scrolling with it)
//formDVC.RefreshRequested += delegate
//{
// formDVC.ReloadComplete();
//};
if (!IsDoctorForm)
{
messageLabel = new UILabel();
formDVC.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIImage.FromBundle("Lock"), UIBarButtonItemStyle.Bordered, delegate (object sender, EventArgs e)
{
//Create Alert
var BackPrompt = UIAlertController.Create("Exit Form", "Administrative use only. Please enter password to continue or tap Cancel", UIAlertControllerStyle.Alert);
BackPrompt.AddTextField((field) =>
{
field.SecureTextEntry = true;
field.Placeholder = "Password";
});
BackPrompt.Add(messageLabel);
BackPrompt.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, action => PopBack(BackPrompt.TextFields[0].Text)));
BackPrompt.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));
//Present Alert
PresentViewController(BackPrompt, true, null);
});
//formDVC.NavigationItem.LeftBarButtonItem.Title = "Back";
}
loadingOverlay.Hide();
return formDVC;
}
void PopBack(string password)
{
bool isValid = password == Constants.Password;
if (isValid)
{
//if (DetailViewController.QuestionsView != null)
//{
// DetailViewController.Title = "";
// DetailViewController.QuestionsView.Clear();
//}
NavigationController.PopViewController(true);
}
else
{
messageLabel.Text = "Wrong password, administrative use only";
var FailAlert = UIAlertController.Create("Error", "Wrong password", UIAlertControllerStyle.Alert);
FailAlert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Cancel, null));
// Present Alert
PresentViewController(FailAlert, true, null);
}
}
void SavePreset(string presetName)
{
// doctorid = 123 / 321
// locationid = 321 / 123
string presetJson = JsonConvert.SerializeObject(SelectedAppointment.SelectedQForm);
var dds = new DynaPadService.DynaPadService();
dds.SaveAnswerPreset(SelectedAppointment.SelectedQForm.FormId, null, SelectedAppointment.ApptDoctorId, true, presetName, presetJson, SelectedAppointment.ApptLocationId);
}
void LoadSectionView(string sectionId, string sectionName, FormSection OrigSection, bool IsDoctorForm)
{
string origSectionJson = JsonConvert.SerializeObject(OrigSection);
DetailViewController.SetDetailItem(new Section(sectionName), sectionId, origSectionJson, IsDoctorForm);
}
void LoadReportView(string sectionId, string sectionName)
{
DetailViewController.SetDetailItem(new Section(sectionName), sectionId, "", false);
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, Resources, etc that aren't in use.
}
void AddNewItem(object sender, EventArgs args)
{
//dataSource.Objects.Insert(0, DateTime.Now);
using (var indexPath = NSIndexPath.FromRowSection(0, 0))
TableView.InsertRows(new[] { indexPath }, UITableViewRowAnimation.Automatic);
}
public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
{
if (segue.Identifier == "showDetail")
{
var indexPath = TableView.IndexPathForSelectedRow;
}
}
class DataSource : UITableViewSource
{
static readonly NSString CellIdentifier = new NSString("Cell");
//readonly List<Section> sectionItems = new List<Section>();
readonly List<RootElement> MenuRoot = new List<RootElement>();
readonly MasterViewController controller;
//public DataSource(List<Section> sections, MasterViewController controller)
public DataSource(RootElement menuRoot, MasterViewController controller)
{
MenuRoot.Add(menuRoot);
this.controller = controller;
}
//public IList<Section> Objects
//{
// get { return sectionItems; }
//}
public IList<RootElement> Objects
{
get { return MenuRoot; }
}
// Customize the number of sections in the table view.
public override nint NumberOfSections(UITableView tableView)
{
return 1;
}
public override nint RowsInSection(UITableView tableview, nint section)
{
return MenuRoot.Count;
}
// Customize the appearance of table view cells.
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var cell = tableView.DequeueReusableCell(CellIdentifier, indexPath);
cell.TextLabel.Text = MenuRoot[indexPath.Row].Caption;
return cell;
}
public override bool CanEditRow(UITableView tableView, NSIndexPath indexPath)
{
// Return false if you do not want the specified item to be editable.
return true;
}
public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
{
if (editingStyle == UITableViewCellEditingStyle.Delete)
{
// Delete the row from the data source.
MenuRoot.RemoveAt(indexPath.Row);
controller.TableView.DeleteRows(new[] { indexPath }, UITableViewRowAnimation.Fade);
}
else if (editingStyle == UITableViewCellEditingStyle.Insert)
{
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
//if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
//controller.DetailViewController.SetDetailItem(sectionItems[indexPath.Row]);
}
}
}
}