2015-06-30 18:12:12 -04:00
|
|
|
|
2015-08-26 00:36:39 -04:00
|
|
|
function icon_or_image_replacement(str, ctx) {
|
|
|
|
str = Ember.get(ctx.contexts[0], str);
|
|
|
|
if (Ember.isEmpty(str)) { return ""; }
|
|
|
|
|
|
|
|
if (str.indexOf('fa-') === 0) {
|
|
|
|
return new Handlebars.SafeString("<i class='fa " + str + "'></i>");
|
|
|
|
} else {
|
|
|
|
return new Handlebars.SafeString("<img src='" + str + "'>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-14 18:34:57 -04:00
|
|
|
function shorthandTinyAvatar(avatar_template, ctx) {
|
2015-08-26 00:36:39 -04:00
|
|
|
return new Handlebars.SafeString(Discourse.Utilities.avatarImg({
|
|
|
|
size: "tiny",
|
|
|
|
extraClasses: '',
|
2015-09-14 18:34:57 -04:00
|
|
|
avatarTemplate: avatar_template
|
2015-08-26 00:36:39 -04:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
const esc = Handlebars.Utils.escapeExpression;
|
2015-06-30 18:12:12 -04:00
|
|
|
|
|
|
|
const QueryRowContentComponent = Ember.Component.extend({
|
|
|
|
tagName: "tr",
|
|
|
|
|
2015-08-25 23:48:19 -04:00
|
|
|
render: function(buffer) {
|
|
|
|
const self = this;
|
2015-06-30 18:12:12 -04:00
|
|
|
const row = this.get('row');
|
2015-08-26 00:36:39 -04:00
|
|
|
const parent = self.get('parent');
|
2015-09-14 19:00:39 -04:00
|
|
|
const fallback = parent.get('fallbackTemplate');
|
2015-08-25 23:48:19 -04:00
|
|
|
|
|
|
|
const parts = this.get('columnTemplates').map(function(t, idx) {
|
2015-08-26 00:36:39 -04:00
|
|
|
const ctx = {};
|
|
|
|
const params = {}
|
2015-08-25 23:48:19 -04:00
|
|
|
if (t.name === "text") {
|
2015-08-26 00:36:39 -04:00
|
|
|
return esc(row[idx]);
|
2015-08-25 23:48:19 -04:00
|
|
|
} else if (t.name === "user") {
|
2015-08-26 00:36:39 -04:00
|
|
|
ctx.user = parent.lookupUser(parseInt(row[idx]));
|
|
|
|
if (!ctx.user) {
|
|
|
|
return esc(row[idx]);
|
|
|
|
}
|
|
|
|
} else if (t.name === "badge") {
|
|
|
|
ctx.badge = parent.lookupBadge(parseInt(row[idx]));
|
|
|
|
params.helpers = {"icon-or-image": icon_or_image_replacement};
|
|
|
|
} else if (t.name === "post") {
|
|
|
|
ctx.post = parent.lookupPost(parseInt(row[idx]));
|
|
|
|
params.helpers = {avatar: shorthandTinyAvatar};
|
2015-08-25 23:48:19 -04:00
|
|
|
} else {
|
2015-08-26 00:36:39 -04:00
|
|
|
ctx.value = row[idx];
|
2015-08-25 23:48:19 -04:00
|
|
|
}
|
|
|
|
|
2015-09-14 19:00:39 -04:00
|
|
|
return new Handlebars.SafeString((t.template || fallback)(ctx, params));
|
2015-06-30 18:12:12 -04:00
|
|
|
});
|
2015-08-25 23:48:19 -04:00
|
|
|
|
|
|
|
buffer.push("<td>" + parts.join("</td><td>") + "</td>");
|
2015-06-30 18:12:12 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default QueryRowContentComponent;
|