git-svn-id: https://msi/svn/firstRepo/WebClient/branches/NewRelease@59 0f545695-f87b-41b6-9a03-7f16563b5454

This commit is contained in:
2016-02-01 17:02:23 +00:00
parent fc7970ec57
commit 7737c750eb
8 changed files with 142 additions and 37 deletions
+82
View File
@@ -0,0 +1,82 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
define(['jquery', 'backbone'],
function ($, Backbone) {
var Images = {
prefix: "images",
getThumb: function (id) {
var val = this._get(id);
if(val.thumb !== "")
return val.thumb;
var response = $.ajax({
url: myManifest.Settings.DefaultURL + "/api/photo/thumbnail/" + id + "/1",
type: 'GET',
async: false
}).responseText;
val.thumb = response;
this._set(id, val);
return val.thumb;
},
getMedium: function (id) {
var val = this._get(id);
if(val.medium !== "")
return val.medium;
var response = $.ajax({
url: myManifest.Settings.DefaultURL + "/api/photo/medium/" + id + "/1",
type: 'GET',
async: false
}).responseText;
val.medium = response;
this._set(id, val);
return val.medium;
},
getFull: function (id) {
var val = this._get(id);
if(val.full !== "")
return val.full;
var response = $.ajax({
url: myManifest.Settings.DefaultURL + "/api/photo/" + id + "/1",
type: 'GET',
async: false
}).responseText;
val.full = response;
this._set(id, val);
return val.full;
},
_set:function(id, item){
var list = JSON.parse(window.localStorage.getItem(this.prefix));
if(list !== null)
{
list[id] = item;
window.localStorage.setItem(this.prefix, JSON.stringify(list));
}
},
_get:function(id){
var ret = null;
var item = JSON.parse(window.localStorage.getItem(this.prefix));
if(item === null){
item = {};
window.localStorage.setItem(this.prefix, JSON.stringify(item));
ret = { thumb: "", medium: "", full:""};
}
else if(item[id] === undefined){
ret = { thumb: "", medium: "", full:""};
}
else{
ret = item[id];
}
return ret;
}
};
return Images;
});