Skip to content

Instantly share code, notes, and snippets.

@savelee
Created July 13, 2016 13:01
Show Gist options
  • Save savelee/2831bb9732f5623333e6baa89aa9142a to your computer and use it in GitHub Desktop.
Save savelee/2831bb9732f5623333e6baa89aa9142a to your computer and use it in GitHub Desktop.
CustomProxy
Ext.define('Engine.model.LastFmResult', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.identifier.Sequential',
'SenchaCandyShared.proxy.lastfm.LastFm'
],
identifier: {
type: 'sequential',
//prefix: 'id_',
seed: -2, //strange?
increment: 1
},
idProperty: 'id',
fields: [{
name: 'id',
type: 'int'
}, {
name: 'playcount',
type: 'int'
}, {
name: 'image'
},
{
name: 'artistimage',
calculate: function(data) {
if(window.location.protocol == "https:"){
return null;
}
if(data.image){
console.log(data.image);
var x = data.image.length;
var url = data.image[x-1]['#text'];
if(Ext.platformTags.cordova || Ext.platformTags.webview){
return url;
} else {
return url.split('http:')[1];
}
}
}
},
{
name: 'artistimagesmall',
calculate: function(data) {
if(window.location.protocol == "https:"){
return null;
}
if(data.image){
var x = data.image.length;
var url = data.image[0]['#text'];
if(Ext.platformTags.cordova || Ext.platformTags.webview){
return url;
} else {
return url.split('http:')[1];
}
}
}
}
],
schema: {}
}, function(model){
var p = "0";
if(document.location.protocol == "https:") p = "1";
//we have to do it this way, because Engine namespace
//could not be available while reading this class
//in the memory.
model.prototype.schema.setNamespace('Engine.model');
model.prototype.schema.setProxy({
type: 'sclastfm',
apiKey: Engine.utils.Constants.APIKEY,
apiSecret: Engine.utils.Constants.APISECRET,
lastFmMethod: 'get{entityName}s',
period: Engine.utils.Constants.PERIOD,
userName: 'savelee',
secure: p,
url: Engine.utils.Constants.LASTFM_API
});
//<debug>
if(Engine.utils.Constants.IS_MOCK){
model.prototype.schema.setProxy({
type: 'ajax',
url: 'mocks/get{entityName}s.json',
secure: p,
reader: {
type: 'json',
rootProperty: 'results.data'
}
});
}
//</debug>
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment