fiveapples 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,16 @@
1
+
2
+
1
3
  sap.ui.define(
2
4
  [
3
- "jquery.sap.global",
4
5
  "sap/ui/core/mvc/Controller",
5
6
  "sap/m/MessageToast",
6
- "sap/m/MessageBox",
7
7
  "sap/ui/commons/Dialog",
8
- "sap/ui/core/routing/History"
8
+ "./FileUpload",
9
+ "./Detail",
10
+ "./Breeder"
9
11
  ],
10
- function(jQuery, Controller, MessageToast, MessageBox, Dialog, History) {
12
+ function(Controller, MessageToast, Dialog,
13
+ FileUpload, Detail, Breeder) {
11
14
  "use strict";
12
15
  return Controller.extend("fivea.controller.Cultivar_Detail", {
13
16
  onInit: function() {
@@ -15,121 +18,133 @@ sap.ui.define(
15
18
  this._oRouter
16
19
  .getRoute("cultivar_detail")
17
20
  .attachPatternMatched(this.onDetailMatched, this);
21
+ this._entity_name = 'Cultivar';
18
22
  },
19
-
20
- onDetailMatched: function(oEvent) {
23
+
24
+ onDetailMatched: function(oEvent) {
21
25
  this._sObjectID = oEvent.getParameter("arguments").id;
22
- var sObjectPath = "/cultivar(" + this._sObjectID + ")";
23
- this._sObjectPath = sObjectPath;
26
+ this._sObjectPath = "/cultivar(" + this._sObjectID + ")";
27
+ this._oImages = this.byId("images");
28
+ this._oAvatar = this.byId("avatar");
29
+
30
+ this.getView().bindElement(this._sObjectPath);
31
+
32
+ this.loadDetails();
33
+
34
+ },
35
+
36
+
37
+ loadImages: function(){
38
+
39
+ var oModel = this.getOwnerComponent().getModel();
40
+ var that = this;
41
+ this._oImages.removeAllContent();
42
+
43
+ function _loadimsuccs(oData, response){
44
+ that.loadimsuccs(oData, response);
45
+ };
46
+
47
+ function _loadimerr(oErr){};
48
+
49
+ oModel.read(this._sObjectPath+"/photo",
50
+ { success: _loadimsuccs,
51
+ error: _loadimerr });
52
+
53
+ },
54
+ loadDetails: function(){
55
+ var oModel = this.getOwnerComponent().getModel();
56
+ var that = this;
57
+ this._oAvatar.setInitials(null);
58
+ this._oAvatar.setSrc(null);
59
+ this._oImages.removeAllContent();
60
+
61
+ function _loaddetailssuccs(oData, response){
62
+
63
+ that.loadimsuccs(oData.photo, response);
64
+ that.loadavsuccs(oData.breeder, response);
65
+
66
+ };
67
+ function _loaddetailserr(oErr){};
68
+
69
+ oModel.read(this._sObjectPath,
70
+ { urlParameters:{$expand: "photo,breeder/avatar"},
71
+ success: _loaddetailssuccs,
72
+ error: _loaddetailserr });
24
73
 
25
- var oView = this.getView();
26
- oView.bindElement({ path: sObjectPath });
27
74
  },
28
- _onBindingChange: function(oEvent) {},
29
75
 
30
76
  onCreatePress: function(evt) {
31
77
  this._oRouter.navTo("cultivar_create");
32
78
  },
33
-
79
+
80
+ onSave: function() {
81
+ Detail.onSave(this);
82
+ },
83
+
34
84
  onDeletePress: function(evt) {
35
- var oView = this.getView();
36
- var oModel = oView.getModel();
37
-
38
- var mParms = {};
39
-
40
- var oDeleteDialog = new sap.ui.commons.Dialog();
41
- oDeleteDialog.setTitle("Delete Cultivar");
42
- var oText = new sap.ui.commons.TextView({
43
- text: "Are you sure to delete this Cultivar?"
44
- });
45
- var _that = this;
46
- oDeleteDialog.addContent(oText);
47
- oDeleteDialog.addButton(
48
- new sap.ui.commons.Button({
49
- text: "Confirm",
50
- press: function() {
51
- var mParms = {};
52
-
53
- mParms.success = function(data, response) {
54
- oDeleteDialog.close();
55
- _that._oRouter.navTo("cultivarList");
56
- // oModel.refresh();
57
- };
58
- mParms.error = function(error) {
59
- oDeleteDialog.close();
60
- MessageToast.show("Delete failed");
61
- };
62
- var sMsg;
63
- sMsg = oView.getBindingContext();
64
- mParms.context = sMsg;
65
- oModel.remove("", mParms);
66
- }
67
- })
68
- );
69
- oDeleteDialog.open();
85
+ Detail.onDeletePress(this, evt);
70
86
  },
71
87
 
72
- onSave: function() {
73
- var oView = this.getView();
74
- var oModel = oView.getModel();
75
- var mParms = {};
76
-
77
-
78
- function onSuccessHandler() {
79
- oModel.refresh();
80
- oModel.updateBindings();
81
- MessageToast.show("Update success");
82
- }
83
-
84
- function onErrorHandler() {
85
- MessageToast.show("Update failed");
86
- }
88
+ loadavsuccs: function(oData, response) {
89
+ // this is the known photo media_src path assuming data is already saved
90
+ var oUrl = "/odata"+this._sObjectPath+"/breeder/avatar/$value";
91
+ if (oData.avatar !== undefined )
92
+ if (Object.keys(oData.avatar).length === 0) {
93
+ this._oAvatar.setSrc(null);
94
+ var oI = oData.first_name.trim()[0] + oData.last_name.trim()[0];
95
+ this._oAvatar.setInitials(oI);
96
+ }
97
+ else{
98
+ // this URL works when we return from the breeder search help
99
+ oUrl = oData.avatar.__metadata.media_src;
100
+ this._oAvatar.setSrc(oUrl);
101
+ }
102
+ else{
103
+ this._oAvatar.setSrc(null);
104
+ }
105
+ },
106
+
107
+
108
+ loadimsuccs: function(oData, response){
109
+ var i, len, oEntry;
110
+ var oList = oData["results"];
111
+ for (i = 0, len = oList.length; i < len; ++i) {
112
+ oEntry = oList[i];
113
+ var oImage = new sap.m.Image(i);
114
+ oImage.setSrc(oEntry.__metadata.media_src);
115
+
116
+ oImage.setDecorative(false);
117
+ oImage.setHeight('200px');
118
+ var oLightBoxItem = new sap.m.LightBoxItem(i) ;
119
+ oLightBoxItem.setImageSrc(oEntry.__metadata.media_src);
120
+ oLightBoxItem.setSubtitle(oEntry.name);
121
+
122
+ var oDetailBox = new sap.m.LightBox();
123
+ oDetailBox.removeAllImageContent() ;
124
+ oDetailBox.addImageContent(oLightBoxItem);
125
+
126
+ oImage.setDetailBox(oDetailBox);
127
+ this._oImages.addContent(oImage);
128
+ }
129
+ this.getView().byId("fileUploader").setValue("");
87
130
 
88
- //var sPath = this._sObjectPath;
89
- //var oData = oModel.getData(sPath);
90
- //console.log("Model data:", oData);
91
- //console.log("Model has pending changes:", oModel.hasPendingChanges());
92
- //console.log("Pending changes:", oModel.getPendingChanges());
93
-
94
- mParms.success = onSuccessHandler;
95
- mParms.error = onErrorHandler;
96
-
97
- oModel.setTokenHandlingEnabled(true);
98
- oModel.updateSecurityToken();
131
+ },
99
132
 
100
- oModel.submitChanges(mParms);
101
- },
102
-
103
133
  onCreateParentForPress: function() {
104
- var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
105
- oRouter.navTo("parent_create_for", { cultivar_id: this._sObjectID });
134
+ this._oRouter.navTo("parent_create_for", {
135
+ cultivar_id: this._sObjectID }
136
+ );
106
137
  },
107
138
  handleBreederPress: function() {
108
139
  var sBreeder_id = this.byId("breeder_id").getValue();
109
- var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
110
- oRouter.navTo("breeder_detail", { id: sBreeder_id });
140
+ this._oRouter.navTo("breeder_detail", { id: sBreeder_id });
111
141
  },
112
142
 
113
- onCheck: function() {
114
- var oView = this.getView();
115
- var oModel = oView.getModel();
116
- var sPath = this._sObjectPath;
117
- var oData = oModel.getData(sPath);
118
- console.log("Model data:", oData);
119
- console.log("Model has pending changes:", oModel.hasPendingChanges());
120
- console.log("Pending changes:", oModel.getPendingChanges());
143
+ navToList: function(){
144
+ this._oRouter.navTo("cultivarList", true);
121
145
  },
122
-
123
146
  onNavBack: function() {
124
- var oHistory = History.getInstance();
125
- var sPreviousHash = oHistory.getPreviousHash();
126
-
127
- if (sPreviousHash !== undefined) {
128
- window.history.go(-1);
129
- } else {
130
- var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
131
- oRouter.navTo("cultivarList", true);
132
- }
147
+ Detail.onNavBack(this);
133
148
  },
134
149
  onParentSelectionChange: function() {
135
150
  var oTable = this.byId("parent_table");
@@ -137,8 +152,7 @@ sap.ui.define(
137
152
 
138
153
  var oCtxt = oTable.getContextByIndex(iIndex);
139
154
  var sToPageParID = oCtxt.getProperty("parent_id");
140
- var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
141
- oRouter.navTo("cultivar_detail", { id: sToPageParID });
155
+ this._oRouter.navTo("cultivar_detail", { id: sToPageParID });
142
156
  },
143
157
  onChildSelectionChange: function() {
144
158
  var oTable = this.byId("child_table");
@@ -146,80 +160,33 @@ sap.ui.define(
146
160
 
147
161
  var oCtxt = oTable.getContextByIndex(iIndex);
148
162
  var sToPageID = oCtxt.getProperty("cultivar_id");
149
- var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
150
- oRouter.navTo("cultivar_detail", { id: sToPageID });
163
+ this._oRouter.navTo("cultivar_detail", { id: sToPageID });
164
+ },
165
+ onBreederCreatePress: function(evt) {
166
+ this._oRouter.navTo("breeder_create");
151
167
  },
152
168
  // Warning: alot of dupl. code with the "cultivar create" controlller
169
+ // --> modularised in Breeder.js
153
170
  inputId: "",
154
171
  inputDescrId: "",
155
- onBreederCreatePress: function(evt) {
156
- var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
157
- oRouter.navTo("breeder_create");
158
- },
159
172
  onBreederIdValueHelp: function(oEvent) {
160
- this.inputId = oEvent.getSource().getId();
161
- this.inputDescrId = this.inputId + "_descr";
162
-
163
- // create value help dialog
164
- if (!this._valueHelpDialog) {
165
- this._valueHelpDialog = sap.ui.xmlfragment(
166
- "fivea.view.BreederOptio",
167
- this
168
- );
169
-
170
- this.getView().addDependent(this._valueHelpDialog);
171
- }
172
-
173
- this._valueHelpDialog.open("");
173
+ Breeder.onIdValueHelp(this, oEvent);
174
174
  },
175
175
 
176
176
  _handleValueHelpSearch: function(evt) {
177
- var sValue = evt.getParameter("value");
178
- var oFilter = new Filter(
179
- "name",
180
- sap.ui.model.FilterOperator.Contains,
181
- sValue
182
- );
183
- evt
184
- .getSource()
185
- .getBinding("items")
186
- .filter([oFilter]);
177
+ Breeder._handleValueHelpSearch(evt);
187
178
  },
188
179
 
189
180
  _handleValueHelpClose: function(evt) {
190
- var oSelectedItem = evt.getParameter("selectedItem");
191
- if (oSelectedItem) {
192
- var IDInput = this.getView().byId(this.inputId);
193
- IDInput.setValue(oSelectedItem.getDescription());
194
-
195
- var oText = this.getView().byId(this.inputDescrId);
196
- oText.setText(oSelectedItem.getTitle());
197
- }
198
- evt
199
- .getSource()
200
- .getBinding("items")
201
- .filter([]);
181
+ Breeder._handleValueHelpClose(this, evt);
202
182
  },
183
+
203
184
  handleUploadComplete: function() {
204
- sap.m.MessageToast.show("File Uploaded");
205
- // var oFilerefresh = this.getView().byId("itemlist");
206
- // oFilerefresh.getModel("Data").refresh(true);
207
- // sap.m.MessageToast.show("File refreshed");
185
+ FileUpload.onComplete(this);
186
+ this.loadImages();
208
187
  },
209
188
  handleUploadPress: function() {
210
- var oFileUploader = this.getView().byId("fileUploader");
211
- if (oFileUploader.getValue() === "") {
212
- MessageToast.show("Please Choose any File");
213
- }
214
- oFileUploader.addHeaderParameter(
215
- new sap.ui.unified.FileUploaderParameter({
216
- name: "SLUG",
217
- value: oFileUploader.getValue()
218
- })
219
- );
220
- oFileUploader.setSendXHR(true);
221
-
222
- oFileUploader.upload();
189
+ FileUpload.onPress(this) ;
223
190
  }
224
191
  });
225
192
  }
@@ -0,0 +1,96 @@
1
+
2
+ /**
3
+ * Common helper/callbacks for entity Detail controller, eg
4
+ * reusable load/save/delete callbacks
5
+ *
6
+ * **/
7
+
8
+ sap.ui.define(["sap/m/MessageToast",
9
+ "sap/ui/commons/Dialog",
10
+ "sap/ui/core/routing/History"],
11
+ function(MessageToast, Dialog, History) {
12
+
13
+ "use strict";
14
+
15
+ return {
16
+ onDeletePress: function(that, evt) {
17
+ var oView = that.getView();
18
+ var oModel = oView.getModel();
19
+
20
+ var mParms = {};
21
+
22
+ var oDeleteDialog = new sap.ui.commons.Dialog();
23
+ oDeleteDialog.setTitle("Delete " + that._entity_name );
24
+ var oText = new sap.ui.commons.TextView({
25
+ text: "Are you sure to delete this " + that._entity_name
26
+ });
27
+
28
+ oDeleteDialog.addContent(oText);
29
+ oDeleteDialog.addButton(
30
+ new sap.ui.commons.Button({
31
+ text: "Confirm",
32
+ press: function() {
33
+ var mParms = {};
34
+
35
+ mParms.success = function(data, response) {
36
+ MessageToast.show("Delete success");
37
+ oDeleteDialog.close();
38
+ that.navToList();
39
+ };
40
+ mParms.error = function(error) {
41
+ oDeleteDialog.close();
42
+ var oMsg = '';
43
+ var errCT = error.headers['Content-Type'];
44
+ if (errCT.indexOf('application/json') == 0 ){
45
+ var ojerr = JSON.parse(error.responseText);
46
+ oMsg = ojerr["odata.error"].message;
47
+ }
48
+ else{
49
+ oMsg = error.message + ' ' + error.statusText
50
+ }
51
+ MessageToast.show("Delete failed : " + oMsg);
52
+ };
53
+ mParms.context = oView.getBindingContext();
54
+ oModel.remove("", mParms);
55
+ }
56
+ })
57
+ );
58
+ oDeleteDialog.open();
59
+ },
60
+ onSave: function(that) {
61
+ var oView = that.getView();
62
+ var oModel = oView.getModel();
63
+ var mParms = {};
64
+
65
+ function onSuccessHandler() {
66
+ oModel.refresh();
67
+ oModel.updateBindings();
68
+ MessageToast.show("Update success");
69
+ }
70
+
71
+ function onErrorHandler() {
72
+ MessageToast.show("Update failed");
73
+ }
74
+
75
+ mParms.success = onSuccessHandler;
76
+ mParms.error = onErrorHandler;
77
+
78
+ oModel.setTokenHandlingEnabled(true);
79
+ oModel.updateSecurityToken();
80
+
81
+ oModel.submitChanges(mParms);
82
+ },
83
+
84
+ onNavBack: function(that) {
85
+ var oHistory = History.getInstance();
86
+ var sPreviousHash = oHistory.getPreviousHash();
87
+
88
+ if (sPreviousHash !== undefined) {
89
+ window.history.go(-1);
90
+ } else {
91
+ that.navToList();
92
+ }
93
+ }
94
+ };
95
+ }
96
+ );
@@ -0,0 +1,40 @@
1
+
2
+ /**
3
+ * Common helper/callbacks for file uploading callbacks
4
+ *
5
+ * **/
6
+
7
+ sap.ui.define(["sap/m/MessageToast","./Base64"],
8
+ function(MessageToast, Base64) {
9
+
10
+ "use strict";
11
+
12
+ return {
13
+ onPress: function(that) {
14
+ var oFileUploader = that.getView().byId("fileUploader");
15
+ if (oFileUploader.getValue() === "") {
16
+ MessageToast.show("Please Choose a file");
17
+ }
18
+ // according to AtomPub spec, the SLUG has to be RFC2047-encoded
19
+ // we use simply the B-Variant
20
+ var oSlugRaw = oFileUploader.getValue();
21
+ var oSlugB2047 = `=?utf-8?b?${Base64.encode(oSlugRaw)}?=`;
22
+ oFileUploader.destroyHeaderParameters();
23
+ oFileUploader.addHeaderParameter(
24
+ new sap.ui.unified.FileUploaderParameter({
25
+ name: "SLUG",
26
+ value: oSlugB2047
27
+ })
28
+ );
29
+ oFileUploader.setSendXHR(true);
30
+
31
+ oFileUploader.upload();
32
+ },
33
+ onComplete: function(that){
34
+ MessageToast.show("File Uploaded");
35
+ var oModel = that.getView().getModel();
36
+ oModel.refresh();
37
+ }
38
+ };
39
+ }
40
+ );