Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send width and height to the api-server #195

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/sa_web/jstemplates/place-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ <h1>{{#if name }}{{ name }}{{^}}{{>location-string .}}{{/if}}</h1>

<section class="place-items">
{{# attachments }}
<div class="place-item place-item-attachment place-attachment-{{ name }}">
<div class="place-item place-item-attachment place-attachment-{{ name }} {{#if ratio}} fixed-ratio {{/if}}"
{{#if ratio}} style="padding-bottom: {{ ratio }}%" {{/if}}>
<img src="{{ file }}" class="place-value place-value-{{ name }}" alt="{{ name }}">
</div>
{{/ attachments }}
Expand Down
11 changes: 11 additions & 0 deletions src/sa_web/static/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,17 @@ ul.recent-points {
margin: 0 1em 0.75em 0;
}

.fixed-ratio {
position: relative;
background-color: #eee;
}

.fixed-ratio img {
position: absolute;
top: 0; bottom: 0; left: 0; right: 0;
min-width: 3em;
}

.place-list .place-label,
.place-list .place-value {
}
Expand Down
14 changes: 10 additions & 4 deletions src/sa_web/static/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,23 @@ var Shareabouts = Shareabouts || {};
var args = normalizeModelArguments(key, val, options),
attrs = _.extend(this.attributes, args.attrs);

return this._attachBlob(attrs.blob, attrs.name, args.options);
return this._attachBlob(attrs.blob, attrs, args.options);
},

_attachBlob: function(blob, name, options) {
_attachBlob: function(blob, attrs, options) {
var formData = new FormData(),
self = this,
progressHandler = S.Util.wrapHandler('progress', this, options.progress),
myXhr = $.ajaxSettings.xhr();
myXhr = $.ajaxSettings.xhr(),
key;

formData.append('file', blob);
formData.append('name', name);

for (key in attrs) {
if (!_(['file', 'blob', 'undefined']).contains(key)) {
formData.append(key, attrs[key]);
}
}

options = options || {};

Expand Down
5 changes: 5 additions & 0 deletions src/sa_web/static/js/views/place-detail-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ var Shareabouts = Shareabouts || {};

// Augment the template data with the attachments list
data.attachments = this.model.attachmentCollection.toJSON();
var i, a;
for (i = 0; i < data.attachments.length; i++) {
a = data.attachments[i];
a.ratio = 100.0 * a.height / a.width;
}
Comment on lines +63 to +67
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuhengd3 What would you think about moving this into a separate function -- something like:

annotateWithAspectRatios: function(attachments) {
  var i, a;
  for (i = 0; i < data.attachments.length; i++) {
    a = data.attachments[i];
    a.ratio = 100.0 * a.height / a.width;
  }
},

Then from we could just call that from here:

this.annotateWithAspectRatios(data.attachments);


this.$el.html(Handlebars.templates['place-detail'](data));

Expand Down
4 changes: 3 additions & 1 deletion src/sa_web/static/js/views/place-form-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ var Shareabouts = Shareabouts || {};
data = {
name: fieldName,
blob: blob,
file: canvas.toDataURL('image/jpeg')
file: canvas.toDataURL('image/jpeg'),
width: canvas.width,
height: canvas.height
};

attachment = self.model.attachmentCollection.find(function(model) {
Expand Down