Skip to content

Commit

Permalink
Merge branch '2375-demo-theme-development' of github.com:okfn/ckan in…
Browse files Browse the repository at this point in the history
…to 2375-demo-theme-development
  • Loading branch information
tobes committed Jul 16, 2012
2 parents 4166adf + 13e549a commit 1463019
Show file tree
Hide file tree
Showing 36 changed files with 4,133 additions and 289 deletions.
19 changes: 19 additions & 0 deletions ckan/public/base/css/main.css
Expand Up @@ -6123,6 +6123,25 @@ textarea {
padding-bottom: 3px;
margin-left: 5px;
}
.resource-upload-field {
position: relative;
}
.resource-upload-field label {
z-index: 0;
}
.resource-upload-field input {
position: absolute;
top: 0;
left: 0;
opacity: 0;
z-index: 1;
cursor: pointer;
}
.resource-upload-field.loading {
display: inline-block;
background: url("../images/loading-spinner.gif") no-repeat center right;
padding-right: 5px;
}
.dataset-item {
border-bottom: 1px dotted #ccc;
padding-bottom: 20px;
Expand Down
Binary file added ckan/public/base/images/loading-spinner.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 114 additions & 0 deletions ckan/public/base/javascript/client.js
@@ -0,0 +1,114 @@
(function (ckan, jQuery) {

function Client() {}

jQuery.extend(Client.prototype, {

/* Requests config options for a file upload.
*
* See: http://docs.ckan.org/en/latest/filestore.html
*
* key - A unique id/filename for the resource.
* success - A callback to be called on successful response.
* error - A callback to be called when the request fails.
*
* Examples
*
* client.getStorageAuth('myfile.jpg', function (data) {
* data.fields;
* });
*
* client.getStorageAuth('myfile.jpg')
* .done(function (data) {
* data.fields;
* })
* .error(function () {
* showError('Something Went Wrong');
* });
*
* Returns a jqXHR promise.
*/
getStorageAuth: function (key, success, error) {
if (!key) {
throw new Error('Client#getStorageAuth() must be called with a key');
}

return jQuery.ajax({
url: '/api/storage/auth/form/' + key,
success: success,
error: error
});
},

/* Requests metadata for a file upload.
*
* See: http://docs.ckan.org/en/latest/filestore.html
*
* key - A unique id/filename for the resource.
* success - A callback to be called on successful response.
* error - A callback to be called when the request fails.
*
* Examples
*
* client.getStorageMetadata('myfile.jpg', function (data) {
* data._format;
* });
*
* Returns a jqXHR promise.
*/
getStorageMetadata: function (key, success, error) {
if (!key) {
throw new Error('Client#getStorageMetadata() must be called with a key');
}

return jQuery.ajax({
url: '/api/storage/metadata/' + key,
success: success,
error: error
});
},

/* Converts the data returned from the storage metadata into keys that
* can be used with a dataset.
*
* key - The key for the stored file.
* meta - The metadata object.
*
* Examples
*
* client.getStorageMetadata('myfile.jpg', function (data) {
* var dataset = client.convertStorageMetadataToResource(data);
* });
*
* Returns an object of dataset keys.
*/
convertStorageMetadataToResource: function (meta) {
var modified = new Date(meta._last_modified);
var modifiedISO = jQuery.date.toISOString(modified);
var filename = meta['filename-original'] || meta.key;
var format = meta._format || filename.split('.').pop();

return {
url: meta._location,
key: meta.key, /* Not strictly Resource data but may be useful */
name: filename,
size: meta._content_length,
last_modified: modifiedISO,
format: format,
mimetype: format,
resource_type: 'file.upload', // Is this standard?
owner: meta['uploaded-by'],
hash: meta._checksum,
cache_url: meta._location,
cache_url_updated: modifiedISO
};
}
});

ckan.sandbox.setup(function (instance) {
instance.client = new Client();
});

ckan.Client = Client;

})(this.ckan, this.jQuery);

0 comments on commit 1463019

Please sign in to comment.