Skip to content

Commit a5a9155

Browse files
Merge branch 'fix/mendix-6'
2 parents f30e598 + f6e068b commit a5a9155

5 files changed

Lines changed: 149 additions & 185 deletions

File tree

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
1-
#GeolocationForPhoneGap
1+
# GeolocationForPhoneGap
22

3-
The Geolocation widget enables PhoneGap native geolocation functionality within your Mendix mobile application. This is a widget that will be functional from Mendix 5.10.
3+
The Geolocation widget enables PhoneGap native geolocation functionality within
4+
your Mendix mobile application. This is a widget that will be functional from
5+
Mendix 5.10.
46

57
## Contributing
68

7-
For more information on contributing to this repository visit [Contributing to a GitHub repository](https://world.mendix.com/display/howto50/Contributing+to+a+GitHub+repository)!
9+
For more information on contributing to this repository visit
10+
[Contributing to a GitHub repository](https://world.mendix.com/display/howto50/Contributing+to+a+GitHub+repository).
811

912
## Configuration
1013

11-
Place the widget in a dataview where you want the button to be placed. Make sure this form is reachable from a mobile application.
14+
Place the widget in a dataview where you want the button to be placed. Make
15+
sure this form is reachable from a mobile application.
1216

1317
### Button
18+
1419
#### Label
20+
1521
The label text that is shown on the button.
1622

1723
#### Class
24+
1825
An optional class to be placed directly on the button dom node.
1926

2027
### Data source
28+
2129
#### Latitude Attribute
30+
2231
The attribute on the dataview object where the latitude should be set to.
2332

2433
#### Longitude Attribute
34+
2535
The attribute on the dataview object where the longitude should be set to.
2636

2737
### Events
38+
2839
#### On change microflow
29-
An optional microflow that will be triggered once the location has been retrieved. It is advised to use this at least with a Refresh in client call, to make sure the UI is updated correctly.
40+
41+
An optional microflow that will be triggered once the location has been
42+
retrieved. It is advised to use this at least with a Refresh in client call, to
43+
make sure the UI is updated correctly.
75.2 KB
Binary file not shown.

src/GeoLocationForPhoneGap/GeoLocationForPhoneGap.xml

Lines changed: 12 additions & 13 deletions
Large diffs are not rendered by default.
Lines changed: 109 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,115 @@
1-
// Dropdown Select Widget
2-
dojo.provide('GeoLocationForPhoneGap.widget.GeoLocationForPhoneGap');
3-
dojo.declare('GeoLocationForPhoneGap.widget.GeoLocationForPhoneGap', mxui.widget._WidgetBase, {
4-
5-
/* Inputargs
6-
7-
this.buttonLabel : string,
8-
this.latAttr : float,
9-
this.longAttr : float,
10-
this.onchangemf : string
11-
12-
*/
13-
14-
// Coding guideline, internal variables start with '_'.
15-
// internal variables.
16-
17-
// *
18-
_result : null,
19-
_button : null,
20-
_hasStarted : false,
21-
_obj : null,
22-
_objSub : null,
23-
24-
// Externally executed mendix function to create widget.
25-
startup: function() {
26-
'use strict';
27-
28-
if (this._hasStarted)
29-
return;
30-
31-
this._hasStarted = true;
32-
33-
// Setup widget
34-
this._setupWX();
35-
36-
// Create childnodes
37-
this._createChildnodes();
38-
39-
// Setup events
40-
this._setupEvents();
41-
42-
},
43-
44-
update : function (obj, callback) {
45-
'use strict';
46-
47-
if(typeof obj === 'string'){
48-
this._contextGuid = obj;
49-
mx.data.get({
50-
guids : [obj],
51-
callback : dojo.hitch(this, function (objArr) {
52-
if (objArr.length === 1)
53-
this._loadData(objArr[0]);
54-
else
55-
console.log('Could not find the object corresponding to the received object ID.')
56-
})
57-
});
58-
} else if(obj === null){
59-
// Sorry no data no show!
60-
console.log('Whoops... the GEO Location has no data!');
61-
} else {
62-
// Attach to data refresh.
63-
if (this._objSub)
64-
this.unsubscribe(this._objSub);
65-
66-
this._objSub = mx.data.subscribe({
67-
guid : obj.getGuid(),
68-
callback : dojo.hitch(this, this.update)
69-
});
70-
// Load data
71-
this._loadData(obj);
72-
}
1+
define([
2+
"mxui/widget/_WidgetBase", "mxui/dom", "dojo/dom-class", "dojo/dom-construct",
3+
"dojo/_base/declare"
4+
], function(_WidgetBase, mxuiDom, dojoClass, dojoConstruct, declare) {
5+
"use strict";
736

74-
if(typeof callback !== 'undefined') {
75-
callback();
76-
}
77-
},
78-
79-
// Loading data
80-
_loadData : function(obj){
81-
this._obj = obj;
82-
},
83-
84-
// Setup
85-
_setupWX: function() {
86-
'use strict';
87-
88-
// Set class for domNode
89-
dojo.addClass(this.domNode, 'wx-geolocation-container');
90-
91-
// Empty domnode of this and appand new input
92-
dojo.empty(this.domNode);
93-
},
94-
95-
_createChildnodes: function() {
96-
'use strict';
97-
98-
// Placeholder container
99-
this._button = mxui.dom.div();
100-
dojo.addClass(this._button, 'wx-mxwxgeolocation-button btn btn-primary');
101-
if (this.buttonClass)
102-
dojo.addClass(this._button, this.buttonClass);
103-
104-
dojo.html.set(this._button, this.buttonLabel || 'GEO Location');
105-
106-
// Add to wxnode
107-
this.domNode.appendChild(this._button);
108-
},
109-
110-
// Internal event setup.
111-
_setupEvents : function() {
112-
'use strict';
113-
114-
// Scope is now inside me variable.
115-
var me = this;
116-
117-
// Attach only one event to dropdown list.
118-
dojo.connect( this._button, "click", dojo.hitch(this, function(evt){
119-
console.log('GEO Location start getting location.');
120-
121-
// The camera function has a success, failure and a reference to this.
122-
navigator.geolocation.getCurrentPosition(
123-
dojo.hitch(this, this._geolocationSuccess),
124-
dojo.hitch(this, this._geolocationFailure),
125-
{timeout: 10000, enableHighAccuracy: true});
126-
}));
127-
128-
},
129-
130-
_geolocationSuccess : function(position){
131-
'use strict';
132-
133-
this._obj.set(this.latAttr, position.coords.latitude);
134-
this._obj.set(this.longAttr, position.coords.longitude);
135-
this._executeMicroflow();
136-
},
137-
138-
_geolocationFailure : function(error){
139-
'use strict';
140-
141-
console.log('GEO Location failure!');
142-
console.log(error.message);
143-
144-
if(this._result){
145-
dojo.html.set(this._result, 'GEO Location failure...' );
146-
} else {
147-
this._result = mxui.dom.div();
148-
dojo.html.set(this._result, 'GEO Location failure...' );
149-
this.domNode.appendChild(this._result);
150-
}
151-
},
7+
return declare("GeoLocationForPhoneGap.widget.GeoLocationForPhoneGap", _WidgetBase, {
8+
9+
buttonLabel: "",
10+
latAttr: 0.0,
11+
longAttr: 0.0,
12+
onchangemf: "",
13+
14+
_result: null,
15+
_button: null,
16+
_hasStarted: false,
17+
_obj: null,
18+
19+
// Externally executed mendix function to create widget.
20+
startup: function() {
21+
if (this._hasStarted)
22+
return;
23+
24+
this._hasStarted = true;
15225

153-
_executeMicroflow : function () {
154-
'use strict';
26+
// Setup widget
27+
this._setupWX();
15528

156-
if (this.onchangemf && this._obj) {
157-
mx.processor.xasAction({
158-
error : function() {},
159-
actionname : this.onchangemf,
160-
applyto : 'selection',
161-
guids : [this._obj.getGuid()]
29+
// Create childnodes
30+
this._createChildnodes();
31+
32+
// Setup events
33+
this._setupEvents();
34+
35+
},
36+
37+
update: function(obj, callback) {
38+
this._obj = obj;
39+
40+
if (callback) callback();
41+
},
42+
43+
// Setup
44+
_setupWX: function() {
45+
// Set class for domNode
46+
dojoClass.add(this.domNode, "wx-geolocation-container");
47+
48+
// Empty domnode of this and appand new input
49+
dojoConstruct.empty(this.domNode);
50+
},
51+
52+
_createChildnodes: function() {
53+
// Placeholder container
54+
this._button = mxuiDom.create("div", {
55+
"class": "wx-mxwxgeolocation-button btn btn-primary"
16256
});
57+
if (this.buttonClass)
58+
dojoClass.add(this._button, this.buttonClass);
59+
60+
this._button.textContent = this.buttonLabel || "GEO Location";
61+
62+
// Add to wxnode
63+
this.domNode.appendChild(this._button);
64+
},
65+
66+
// Internal event setup.
67+
_setupEvents: function() {
68+
this.connect(this._button, "click", function(evt) {
69+
console.log("GEO Location start getting location.");
70+
71+
navigator.geolocation.getCurrentPosition(
72+
this._geolocationSuccess.bind(this),
73+
this._geolocationFailure.bind(this), {
74+
timeout: 10000,
75+
enableHighAccuracy: true
76+
});
77+
});
78+
},
79+
80+
_geolocationSuccess: function(position) {
81+
this._obj.set(this.latAttr, position.coords.latitude);
82+
this._obj.set(this.longAttr, position.coords.longitude);
83+
this._executeMicroflow();
84+
},
85+
86+
_geolocationFailure: function(error) {
87+
console.log("GEO Location failure!");
88+
console.log(error.message);
89+
90+
if (this._result) {
91+
this._result.textContent = "GEO Location failure...";
92+
} else {
93+
this._result = mxuiDom.create("div");
94+
this._result.textContent = "GEO Location failure...";
95+
this.domNode.appendChild(this._result);
96+
}
97+
},
98+
99+
_executeMicroflow: function() {
100+
if (this.onchangemf && this._obj) {
101+
mx.data.action({
102+
params: {
103+
actionname: this.onchangemf,
104+
applyto: "selection",
105+
guids: [ this._obj.getGuid() ]
106+
},
107+
error: function() {},
108+
});
109+
}
163110
}
164-
}
111+
});
165112
});
113+
114+
// Compatibility with older mendix versions.
115+
require([ "GeoLocationForPhoneGap/widget/GeoLocationForPhoneGap" ], function() {});

src/package.xml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="Geo Location For PhoneGap" version="2.0" xmlns="http://www.mendix.com/clientModule/1.0/">
4-
<widgetFiles>
5-
<widgetFile path="GeoLocationForPhoneGap/GeoLocationForPhoneGap.xml"/>
6-
</widgetFiles>
7-
<files>
8-
<file path="GeoLocationForPhoneGap/widget/"/>
9-
</files>
10-
</clientModule>
3+
<clientModule xmlns="http://www.mendix.com/clientModule/1.0/"
4+
name="Geo Location For PhoneGap" version="2.2">
5+
<widgetFiles>
6+
<widgetFile path="GeoLocationForPhoneGap/GeoLocationForPhoneGap.xml"/>
7+
</widgetFiles>
8+
<files>
9+
<file path="GeoLocationForPhoneGap/widget/"/>
10+
</files>
11+
</clientModule>
1112
</package>

0 commit comments

Comments
 (0)