|
@@ -8,11 +8,15 @@ |
8 |
8 |
|
using System.Linq; |
9 |
9 |
|
using System.Runtime.InteropServices.WindowsRuntime; |
10 |
10 |
|
using System.Text.RegularExpressions; |
|
11 |
+ |
using System.Threading.Tasks; |
|
12 |
+ |
using Windows.ApplicationModel.Resources; |
|
13 |
+ |
using Windows.Devices.Geolocation; |
11 |
14 |
|
using Windows.Foundation; |
12 |
15 |
|
using Windows.Foundation.Collections; |
13 |
16 |
|
using Windows.Graphics.Display; |
14 |
17 |
|
using Windows.UI; |
15 |
18 |
|
using Windows.UI.Core; |
|
19 |
+ |
using Windows.UI.Popups; |
16 |
20 |
|
using Windows.UI.ViewManagement; |
17 |
21 |
|
using Windows.UI.Xaml; |
18 |
22 |
|
using Windows.UI.Xaml.Controls; |
|
@@ -35,6 +39,8 @@ |
35 |
39 |
|
private ObservableDictionary defaultViewModel = new ObservableDictionary(); |
36 |
40 |
|
private SiteType selectedSiteType; |
37 |
41 |
|
private SmartChargeAPI SMA; |
|
42 |
+ |
private ResourceLoader resourceLoader; |
|
43 |
+ |
private Site currentSite; |
38 |
44 |
|
|
39 |
45 |
|
public ModifySitePage() |
40 |
46 |
|
{ |
|
@@ -44,6 +50,8 @@ |
44 |
50 |
|
this.navigationHelper.LoadState += this.NavigationHelper_LoadState; |
45 |
51 |
|
this.navigationHelper.SaveState += this.NavigationHelper_SaveState; |
46 |
52 |
|
this.SMA = SmartChargeAPI.Instance; |
|
53 |
+ |
|
|
54 |
+ |
this.resourceLoader = ResourceLoader.GetForCurrentView("Resources"); |
47 |
55 |
|
} |
48 |
56 |
|
|
49 |
57 |
|
/// <summary> |
|
@@ -76,9 +84,61 @@ |
76 |
84 |
|
/// session. The state will be null the first time a page is visited.</param> |
77 |
85 |
|
private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e) |
78 |
86 |
|
{ |
79 |
|
- |
|
|
87 |
+ |
showLoading(); |
80 |
88 |
|
List<SiteType> types = await this.SMA.getSiteTypesList(); |
81 |
89 |
|
this.SiteTypeList.ItemsSource = types; |
|
90 |
+ |
List<Site> userSites = await this.SMA.GetUserSites(); |
|
91 |
+ |
string avatarUrl = await this.SMA.GetUserAvatar(this.SMA.user.Id); |
|
92 |
+ |
|
|
93 |
+ |
if (avatarUrl != "") |
|
94 |
+ |
{ |
|
95 |
+ |
this.AvatarPicker.setImageSource(new Uri(avatarUrl)); |
|
96 |
+ |
} |
|
97 |
+ |
|
|
98 |
+ |
|
|
99 |
+ |
if (userSites != null && userSites.Count > 0) |
|
100 |
+ |
{ |
|
101 |
+ |
this.currentSite = userSites[0]; |
|
102 |
+ |
await this.FillFields(this.currentSite); |
|
103 |
+ |
List<string> siteImages = await this.SMA.GetSiteImages(this.currentSite); |
|
104 |
+ |
List<Uri> siteImagesUri = new List<Uri>(); |
|
105 |
+ |
for (int i = 0; i < siteImages.Count; i++) |
|
106 |
+ |
{ |
|
107 |
+ |
siteImagesUri.Add(new Uri(siteImages[i])); |
|
108 |
+ |
} |
|
109 |
+ |
this.SiteImagePicker.setInitialImages(siteImagesUri); |
|
110 |
+ |
|
|
111 |
+ |
|
|
112 |
+ |
|
|
113 |
+ |
} |
|
114 |
+ |
else |
|
115 |
+ |
{ |
|
116 |
+ |
MessageDialog dialogbox = new MessageDialog(resourceLoader.GetString("NoSiteToModify")); |
|
117 |
+ |
|
|
118 |
+ |
//OK Button |
|
119 |
+ |
UICommand okBtn = new UICommand(resourceLoader.GetString("OK")); |
|
120 |
+ |
okBtn.Invoked = (s) => |
|
121 |
+ |
{ |
|
122 |
+ |
goToUserPage(); |
|
123 |
+ |
}; |
|
124 |
+ |
dialogbox.Commands.Add(okBtn); |
|
125 |
+ |
} |
|
126 |
+ |
|
|
127 |
+ |
hideLoading(); |
|
128 |
+ |
} |
|
129 |
+ |
|
|
130 |
+ |
private async Task FillFields(Site s) |
|
131 |
+ |
{ |
|
132 |
+ |
this.SiteNameInput.Text = s.Name != null ? s.Name : ""; |
|
133 |
+ |
this.SiteDescriptionInput.Text = s.Description != null ? s.Description : ""; |
|
134 |
+ |
this.PhoneNumberInput.Text = s.PhoneNumber != null ? s.PhoneNumber : ""; |
|
135 |
+ |
this.EmailInput.Text = s.Email != null ? s.Email : ""; |
|
136 |
+ |
this.NumberOfChargersTextBox.Text = s.Chargers + ""; |
|
137 |
+ |
this.SiteWebsiteTextBox.Text = s.WebSite != null ? s.WebSite : ""; |
|
138 |
+ |
this.selectedSiteType = s.Type; |
|
139 |
+ |
this.SiteTypeButton.Content = "Tipologia locale : " + s.Type.Label; |
|
140 |
+ |
await this.SitePositionSelector.SetInitialPosition(s.Position); |
|
141 |
+ |
|
82 |
142 |
|
} |
83 |
143 |
|
|
84 |
144 |
|
/// <summary> |
|
@@ -130,7 +190,7 @@ |
130 |
190 |
|
{ |
131 |
191 |
|
|
132 |
192 |
|
Site newSite = new Site() |
133 |
|
- |
{ |
|
193 |
+ |
{ Id = this.currentSite.Id, |
134 |
194 |
|
Name = this.SiteNameInput.Text, |
135 |
195 |
|
Description = this.SiteDescriptionInput.Text, |
136 |
196 |
|
Type = this.selectedSiteType, |