Skip to content

Commit

Permalink
change auto to autoFire and add skipToken.
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthijsKok committed Sep 21, 2017
1 parent ad30fb0 commit daeb3ef
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 90 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lancie-ajax",
"version": "1.0.1",
"version": "2.1.0",
"description": "iron-ajax element specified for the lancie frontends",
"main": "lancie-ajax.html",
"dependencies": {
Expand Down
184 changes: 95 additions & 89 deletions lancie-ajax.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,108 +30,114 @@
></iron-ajax>
</template>
<script>
(function() {
'use strict';
(function() {
'use strict';

var token, ajax = [];
var token, ajax = [];

Polymer({
is: 'lancie-ajax',
Polymer({
is: 'lancie-ajax',

properties: {
contenttype: {
type: String,
value: 'application/json',
notify: true
},
refurl: {
type: String,
value: '',
notify: true
},
handleAs: {
type: String,
value: 'json',
notify: true
},
auto: {
type: Boolean,
value: false
},
isuser: {
type: Boolean,
value: false
},
loading: {
type: Boolean,
notify: true,
value: false
},
params: {
type: Object,
value: {}
},
method: {
type: String,
value: 'GET'
},
lastResponse: {
type: Object,
notify: true
},
body: {
type: Object
properties: {
contenttype: {
type: String,
value: 'application/json',
notify: true
},
refurl: {
type: String,
value: '',
notify: true
},
handleAs: {
type: String,
value: 'json',
notify: true
},
autoFire: {
type: Boolean,
value: false
},
skipToken: {
type: Boolean,
value: false
},
isuser: {
type: Boolean,
value: false
},
loading: {
type: Boolean,
notify: true,
value: false
},
params: {
type: Object,
value: {}
},
method: {
type: String,
value: 'GET'
},
lastResponse: {
type: Object,
notify: true
},
body: {
type: Object
},
token: {
type: String,
value: '',
notify: true,
}
},
token: {
type: String,
value: '',
notify: true,
}
},

/* STATIC CALL */
injectToken: function(newToken) {
token = newToken;
this.token = token;
/* STATIC CALL */
injectToken: function(newToken) {
token = newToken;

for (var i = 0; i < ajax.length; i++) {
ajax[i](token);
}
},
for (let i = 0; i < ajax.length; i++) {
ajax[i](token);
}
},

attached: function() {
if (!token) {
ajax.push(function(newToken) {
this.token = newToken;
attached: function() {
if (this.skipToken && this.autoFire) {
this.generateRequest();
return;
}

if (this.auto) {
if (token) {
this.token = token;
if (this.autoFire) {
this.generateRequest();
}
}.bind(this));
} else {
this.token = token;

if (this.auto) {
this.generateRequest();
} else {
ajax.push(function(newToken) {
this.token = newToken;
if (this.autoFire) {
this.generateRequest();
}
}.bind(this));
}
}
},
},

createHeader: function(token, contenttype) {
return {
'Content-Type': contenttype,
'X-Auth-Token': token,
};
},
createHeader: function(token, contenttype) {
return {
'Content-Type': contenttype,
'X-Auth-Token': token,
};
},

handleResponse: function(event) {
this.fire('lancie-ajax', event.detail);
},
handleResponse: function(event) {
this.fire('lancie-ajax', event.detail);
},

generateRequest: function() {
this.$.ajax.generateRequest();
},
});
})();
generateRequest: function() {
this.$.ajax.generateRequest();
},
});
})();
</script>
</dom-module>

0 comments on commit daeb3ef

Please sign in to comment.