2013-09-07 19:50:43 +04:00
|
|
|
(function () {
|
2015-04-14 19:02:33 +03:00
|
|
|
var ns = $.namespace('pskl.service');
|
2013-09-30 01:26:09 +04:00
|
|
|
ns.ImageUploadService = function () {};
|
|
|
|
ns.ImageUploadService.prototype.init = function () {};
|
2013-09-07 19:50:43 +04:00
|
|
|
|
|
|
|
/**
|
2015-04-14 19:02:33 +03:00
|
|
|
* Upload a base64 image data to distant service.
|
|
|
|
* If successful, will call provided callback with the image URL as first argument;
|
2013-09-07 19:50:43 +04:00
|
|
|
* @param {String} imageData base64 image data (such as the return value of canvas.toDataUrl())
|
2014-08-24 00:45:52 +04:00
|
|
|
* @param {Function} success success callback. 1st argument will be the uploaded image URL
|
|
|
|
* @param {Function} error error callback
|
2013-09-07 19:50:43 +04:00
|
|
|
*/
|
2014-08-24 00:45:52 +04:00
|
|
|
ns.ImageUploadService.prototype.upload = function (imageData, success, error) {
|
|
|
|
var data = {
|
|
|
|
data : imageData
|
2013-09-07 19:50:43 +04:00
|
|
|
};
|
|
|
|
|
2014-08-24 00:45:52 +04:00
|
|
|
var wrappedSuccess = function (response) {
|
|
|
|
success(Constants.IMAGE_SERVICE_GET_URL + response.responseText);
|
|
|
|
};
|
|
|
|
|
|
|
|
pskl.utils.Xhr.post(Constants.IMAGE_SERVICE_UPLOAD_URL, data, wrappedSuccess, error);
|
2013-09-07 19:50:43 +04:00
|
|
|
};
|
2013-09-30 01:26:09 +04:00
|
|
|
})();
|