fiveapples 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,11 +18,11 @@ sap.ui.define(
18
18
  var iIndex = oTable.getSelectedIndex();
19
19
 
20
20
  var oCtxt = oTable.getContextByIndex(iIndex);
21
- var sToPageId = oCtxt.getProperty("id");
22
-
23
- var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
24
- // MessageToast.show(" navTo cultivar_detail -->"+sToPageId);
25
- oRouter.navTo("breeder_detail", { id: sToPageId });
21
+ if (oCtxt) {
22
+ var sToPageId = oCtxt.getProperty("id");
23
+ var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
24
+ oRouter.navTo("breeder_detail", { id: sToPageId });
25
+ }
26
26
  }
27
27
  });
28
28
  }
@@ -2,68 +2,39 @@ sap.ui.define(
2
2
  [
3
3
  "sap/ui/core/mvc/Controller",
4
4
  "sap/m/MessageToast",
5
- "sap/ui/core/routing/History"
5
+ "./Detail",
6
+ "./Create"
6
7
  ],
7
- function(Controller, MessageToast, History) {
8
+ function(Controller, MessageToast, Detail, Create) {
8
9
  "use strict";
9
10
  return Controller.extend("fivea.controller.Breeder_Create", {
10
11
  onInit: function() {
11
12
  this._oRouter = sap.ui.core.UIComponent.getRouterFor(this);
13
+ this._oRouter
14
+ .getRoute("breeder_create")
15
+ .attachPatternMatched(this.createEntry, this);
16
+ },
17
+ createEntry: function(){
12
18
  var oView = this.getView();
13
19
  var oModel = this.getOwnerComponent().getModel();
14
20
  var oContext = oModel.createEntry("/breeder", {});
15
21
  oView.setModel(oModel);
16
- oView.setBindingContext(oContext);
22
+ oView.setBindingContext(oContext);
17
23
  },
18
- onNavPress: function() {
19
- var oHistory = History.getInstance();
20
- var sPreviousHash = oHistory.getPreviousHash();
21
-
22
- if (sPreviousHash !== undefined) {
23
- // history contains a previous entry
24
- window.history.go(-1);
25
- } else {
26
- this._oRouter.navTo("breederList");
27
- }
24
+ navToList: function(){
25
+ this._oRouter.navTo("breederList", true);
28
26
  },
29
- onCreate: function() {
30
- var oModel = this.getView().getModel();
31
- var _oRouter = this._oRouter;
32
-
33
-
34
- function onSuccessHandler(data) {
35
- MessageToast.show("Create success");
36
- // TODO: isnt this data access OData version dependant?
37
- // OneWay is simply
38
- // var new_entity_tab = data
39
-
40
- // The TwoWay way. No this is not ridiculous. You tell me the better way ?
41
- var new_entity_tab = data["__batchResponses"]["0"].__changeResponses["0"].data;
42
- _oRouter.navTo("breeder_detail", { id: new_entity_tab["results"][0].id });
43
- }
44
- function onErrorHandler() {
45
- MessageToast.show("Create failed");
46
- }
47
- var mParms = {};
48
-
49
- mParms.success = onSuccessHandler;
50
- mParms.error = onErrorHandler;
51
-
52
- oModel.submitChanges(mParms);
53
-
54
-
55
- },
56
-
57
27
  onNavBack: function() {
58
- var oHistory = History.getInstance();
59
- var sPreviousHash = oHistory.getPreviousHash();
28
+ Detail.onNavBack(this);
29
+ },
30
+ onCreatePress: function() {
31
+ Create.onPress(this);
32
+ },
33
+ navToDetail: function(oData){
34
+ // navigate to detail page but dont keep create
35
+ // page history (hist. replace)
60
36
 
61
- if (sPreviousHash !== undefined) {
62
- window.history.go(-1);
63
- } else {
64
- var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
65
- oRouter.navTo("breederList", true);
66
- }
37
+ this._oRouter.navTo("breeder_detail", { id: oData.id }, {}, true);
67
38
  }
68
39
  });
69
40
  }
@@ -1,10 +1,12 @@
1
+
1
2
  sap.ui.define(
2
3
  [
3
4
  "sap/ui/core/mvc/Controller",
4
5
  "sap/m/MessageToast",
5
- "sap/ui/core/routing/History"
6
+ "./FileUpload",
7
+ "./Detail"
6
8
  ],
7
- function(Controller, MessageToast, History) {
9
+ function(Controller, MessageToast, FileUpload, Detail) {
8
10
  "use strict";
9
11
  return Controller.extend("fivea.controller.Breeder_Detail", {
10
12
  onInit: function() {
@@ -12,6 +14,7 @@ sap.ui.define(
12
14
  this._oRouter
13
15
  .getRoute("breeder_detail")
14
16
  .attachPatternMatched(this.onDetailMatched, this);
17
+ this._entity_name = 'Breeder';
15
18
  },
16
19
  onDetailMatched: function(oEvent) {
17
20
  this._sObjectID = oEvent.getParameter("arguments").id;
@@ -20,9 +23,57 @@ sap.ui.define(
20
23
  var oView = this.getView();
21
24
 
22
25
  oView.bindElement({ path: sObjectPath });
26
+
27
+ var oAvatar = this.byId("avatar");
28
+ this._sAvatar = oAvatar;
29
+ this._sAvatarImage = false;
30
+ this.loadAvatar();
31
+ },
32
+ loadAvatar: function() {
33
+ var sImgsPath = this._sObjectPath + "/avatar";
34
+ var that = this;
35
+ var oView = this.getView();
36
+ var oModel = oView.getModel();
37
+ var oAvatar = that.byId("avatar");
38
+
39
+ function _loadavsuccs(oData, response) {
40
+ // UploadUrl for Avatar creation (first time)
41
+ var oUrl = "/odata"+that._sObjectPath+"/avatar";
42
+ var oSrc = null;
43
+ if (oData.avatar !== undefined ){
44
+ if (Object.keys(oData.avatar).length === 0) {
45
+ var oI = oData.first_name.trim()[0] + oData.last_name.trim()[0];
46
+ oAvatar.setInitials(oI);
47
+ }
48
+ else{
49
+ oUrl = "/odata"+that._sObjectPath+"/avatar/$value";
50
+ oSrc = oData.avatar.__metadata.media_src;
51
+ // Avatar was already uploaded. UploadUrl should be for an Update
52
+ // but it's not yet implemented in safrano 0.4
53
+ // (POST /Photo(4)/$value ...safrano-todo)
54
+ oUrl = oSrc
55
+
56
+ }
57
+ }
58
+ oAvatar.setSrc(oSrc);
59
+ oView.byId("fileUploader").setUploadUrl(oUrl);
60
+ oView.byId("fileUploader").setValue("");
61
+ }
62
+
63
+ function _loadaverr(oErr) { }
64
+
65
+ oModel.read(this._sObjectPath,
66
+ { urlParameters:{$expand: "avatar"},
67
+ success: _loadavsuccs,
68
+ error: _loadaverr });
69
+ },
70
+ handleUploadComplete: function() {
71
+ FileUpload.onComplete(this);
72
+ this.loadAvatar();
73
+ },
74
+ handleUploadPress: function() {
75
+ FileUpload.onPress(this) ;
23
76
  },
24
-
25
- _onBindingChange: function(oEvent) {},
26
77
 
27
78
  onCultivarSelectionChange: function() {
28
79
  var oTable = this.byId("breeder_cultivar_table");
@@ -30,99 +81,19 @@ sap.ui.define(
30
81
 
31
82
  var oCtxt = oTable.getContextByIndex(iIndex);
32
83
  var sToPageParID = oCtxt.getProperty("id");
33
- var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
34
- oRouter.navTo("cultivar_detail", { id: sToPageParID });
84
+ this._oRouter.navTo("cultivar_detail", { id: sToPageParID });
35
85
  },
36
-
37
86
  onDeletePress: function(evt) {
38
- var oView = this.getView();
39
- var oModel = oView.getModel();
40
-
41
- var mParms = {};
42
-
43
- var oDeleteDialog = new sap.ui.commons.Dialog();
44
- oDeleteDialog.setTitle("Delete Breeder");
45
- var oText = new sap.ui.commons.TextView({
46
- text: "Are you sure to delete this Breeder?"
47
- });
48
- var _that = this;
49
- oDeleteDialog.addContent(oText);
50
- oDeleteDialog.addButton(
51
- new sap.ui.commons.Button({
52
- text: "Confirm",
53
- press: function() {
54
- var mParms = {};
55
-
56
- mParms.success = function(data, response) {
57
- oDeleteDialog.close();
58
- _that._oRouter.navTo("breederList");
59
- // oModel.refresh();
60
- };
61
- mParms.error = function(error) {
62
- oDeleteDialog.close();
63
- MessageToast.show("Delete failed");
64
- };
65
- var sMsg;
66
- sMsg = oView.getBindingContext();
67
- mParms.context = sMsg;
68
- oModel.remove("", mParms);
69
- }
70
- })
71
- );
72
- oDeleteDialog.open();
87
+ Detail.onDeletePress(this, evt);
73
88
  },
74
-
75
89
  onSave: function() {
76
- var oView = this.getView();
77
- var oModel = oView.getModel();
78
- var mParms = {};
79
-
80
-
81
- function onSuccessHandler() {
82
- oModel.refresh();
83
- oModel.updateBindings();
84
- MessageToast.show("Update success");
85
- }
86
-
87
- function onErrorHandler() {
88
- MessageToast.show("Update failed");
89
- }
90
-
91
- //var sPath = this._sObjectPath;
92
- //var oData = oModel.getData(sPath);
93
- //console.log("Model data:", oData);
94
- //console.log("Model has pending changes:", oModel.hasPendingChanges());
95
- //console.log("Pending changes:", oModel.getPendingChanges());
96
-
97
- mParms.success = onSuccessHandler;
98
- mParms.error = onErrorHandler;
99
-
100
- oModel.setTokenHandlingEnabled(true);
101
- oModel.updateSecurityToken();
102
-
103
- oModel.submitChanges(mParms);
104
- },
105
-
106
- onCheck: function() {
107
- var oView = this.getView();
108
- var oModel = oView.getModel();
109
- var sPath = this._sObjectPath;
110
- var oData = oModel.getData(sPath);
111
- console.log("Model data:", oData);
112
- console.log("Model has pending changes:", oModel.hasPendingChanges());
113
- console.log("Pending changes:", oModel.getPendingChanges());
90
+ Detail.onSave(this);
91
+ },
92
+ navToList: function(){
93
+ this._oRouter.navTo("breederList", true);
114
94
  },
115
-
116
95
  onNavBack: function() {
117
- var oHistory = History.getInstance();
118
- var sPreviousHash = oHistory.getPreviousHash();
119
-
120
- if (sPreviousHash !== undefined) {
121
- window.history.go(-1);
122
- } else {
123
- var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
124
- oRouter.navTo("breederList", true);
125
- }
96
+ Detail.onNavBack(this);
126
97
  }
127
98
  });
128
99
  }
@@ -0,0 +1,41 @@
1
+
2
+ /**
3
+ * Common helper/callbacks for entity creation
4
+ *
5
+ * **/
6
+
7
+ sap.ui.define(["sap/m/MessageToast"],
8
+ function(MessageToast) {
9
+
10
+ "use strict";
11
+
12
+ return {
13
+ onPress: function(that) {
14
+
15
+ var oModel = that.getView().getModel();
16
+
17
+ function onSuccessHandler(data) {
18
+ MessageToast.show("Create success");
19
+ // isnt this data access OData version dependant?
20
+ // OneWay is simply
21
+ // var new_entity_tab = data
22
+
23
+ // The TwoWay way. No this is not ridiculous.
24
+ // You tell me the better way ?
25
+
26
+ var entity_tab = data.__batchResponses[0].__changeResponses[0].data;
27
+ that.navToDetail(entity_tab.results[0]);
28
+ }
29
+ function onErrorHandler() {
30
+ MessageToast.show("Create failed");
31
+ }
32
+ var mParms = {};
33
+
34
+ mParms.success = onSuccessHandler;
35
+ mParms.error = onErrorHandler;
36
+
37
+ oModel.submitChanges(mParms);
38
+ },
39
+ };
40
+ }
41
+ );
@@ -19,10 +19,11 @@ sap.ui.define(
19
19
  var iIndex = oTable.getSelectedIndex();
20
20
 
21
21
  var oCtxt = oTable.getContextByIndex(iIndex);
22
- var sToPageId = oCtxt.getProperty("id");
23
-
24
- var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
25
- oRouter.navTo("cultivar_detail", { id: sToPageId });
22
+ if (oCtxt) {
23
+ var sToPageId = oCtxt.getProperty("id");
24
+ var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
25
+ oRouter.navTo("cultivar_detail", { id: sToPageId });
26
+ }
26
27
  }
27
28
  });
28
29
  }
@@ -2,108 +2,53 @@ sap.ui.define(
2
2
  [
3
3
  "sap/ui/core/mvc/Controller",
4
4
  "sap/m/MessageToast",
5
- "sap/ui/core/routing/History"
5
+ "./Detail",
6
+ "./Breeder",
7
+ "./Create"
6
8
  ],
7
- function(Controller, MessageToast, History) {
9
+ function(Controller, MessageToast, Detail, Breeder, Create) {
8
10
  "use strict";
9
11
  return Controller.extend("fivea.controller.Cultivar_Create", {
10
12
  onInit: function() {
11
- var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
12
- this._oRouter = oRouter;
13
-
13
+ this._oRouter = sap.ui.core.UIComponent.getRouterFor(this);
14
+ this._oRouter
15
+ .getRoute("cultivar_create")
16
+ .attachPatternMatched(this.createEntry, this);
17
+ },
18
+ createEntry: function(){
14
19
  var oView = this.getView();
15
20
  var oModel = this.getOwnerComponent().getModel();
16
21
  var oContext = oModel.createEntry("/cultivar", {});
17
22
  oView.setModel(oModel);
18
- oView.setBindingContext(oContext);
23
+ oView.setBindingContext(oContext);
19
24
  },
20
-
21
- onCreatePress: function() {
22
-
23
- var oModel = this.getView().getModel();
24
- var _oRouter = this._oRouter;
25
-
26
-
27
- function onSuccessHandler(data) {
28
- MessageToast.show("Create success");
29
- // TODO: isnt this data access OData version dependant?
30
- // OneWay is simply
31
- // var new_entity_tab = data
32
-
33
- // The TwoWay way. No this is not ridiculous. You tell me the better way ?
34
- var new_entity_tab = data["__batchResponses"]["0"].__changeResponses["0"].data;
35
- _oRouter.navTo("cultivar_detail", { id: new_entity_tab["results"][0].id });
36
- }
37
- function onErrorHandler() {
38
- MessageToast.show("Create failed");
39
- }
40
- var mParms = {};
41
-
42
- mParms.success = onSuccessHandler;
43
- mParms.error = onErrorHandler;
44
-
45
- oModel.submitChanges(mParms);
25
+ onCreatePress: function() {
26
+ Create.onPress(this);
27
+ },
28
+ navToDetail: function(oData){
29
+ // navigate to detail page but dont keep create
30
+ // page history (hist. replace)
46
31
 
47
-
32
+ this._oRouter.navTo("cultivar_detail", { id: oData.id }, {}, true);
33
+ },
34
+ navToList: function(){
35
+ this._oRouter.navTo("cultivarList", true);
48
36
  },
49
-
50
37
  onNavBack: function() {
51
- var oHistory = History.getInstance();
52
- var sPreviousHash = oHistory.getPreviousHash();
53
-
54
- if (sPreviousHash !== undefined) {
55
- window.history.go(-1);
56
- } else {
57
- this._oRouter.navTo("cultivarList", true);
58
- }
38
+ Detail.onNavBack(this);
59
39
  },
60
-
61
40
  inputId: "",
62
41
  inputDescrId: "",
63
-
64
42
  onBreederIdValueHelp: function(oEvent) {
65
- this.inputId = oEvent.getSource().getId();
66
- this.inputDescrId = this.inputId + "_descr";
67
-
68
- // create value help dialog
69
- if (!this._valueHelpDialog) {
70
- this._valueHelpDialog = sap.ui.xmlfragment(
71
- "fivea.view.BreederOptio",
72
- this
73
- );
74
-
75
- this.getView().addDependent(this._valueHelpDialog);
76
- }
77
-
78
- this._valueHelpDialog.open("");
43
+ Breeder.onIdValueHelp(this, oEvent);
79
44
  },
80
45
 
81
46
  _handleValueHelpSearch: function(evt) {
82
- var sValue = evt.getParameter("value");
83
- var oFilter = new Filter(
84
- "name",
85
- sap.ui.model.FilterOperator.Contains,
86
- sValue
87
- );
88
- evt
89
- .getSource()
90
- .getBinding("items")
91
- .filter([oFilter]);
47
+ Breeder._handleValueHelpSearch(evt);
92
48
  },
93
49
 
94
50
  _handleValueHelpClose: function(evt) {
95
- var oSelectedItem = evt.getParameter("selectedItem");
96
- if (oSelectedItem) {
97
- var IDInput = this.getView().byId(this.inputId);
98
- IDInput.setValue(oSelectedItem.getDescription());
99
-
100
- var oText = this.getView().byId(this.inputDescrId);
101
- oText.setText(oSelectedItem.getTitle());
102
- }
103
- evt
104
- .getSource()
105
- .getBinding("items")
106
- .filter([]);
51
+ Breeder._handleValueHelpClose(this, evt);
107
52
  }
108
53
  });
109
54
  }