Skip to content

Instantly share code, notes, and snippets.

@Alavi1412
Created February 4, 2017 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alavi1412/f3b64aa9753288759ab5c299c1018093 to your computer and use it in GitHub Desktop.
Save Alavi1412/f3b64aa9753288759ab5c299c1018093 to your computer and use it in GitHub Desktop.
import { createWidget } from 'discourse/widgets/widget';
import { h } from 'virtual-dom';
import { avatarImg } from 'discourse/widgets/post';
import { cook } from 'discourse/lib/text';
import RawHtml from 'discourse/widgets/raw-html';
import showModal from 'discourse/lib/show-modal';
import Composer from 'discourse/models/composer';
import { getOwner } from 'discourse-common/lib/get-owner';
export default createWidget('profile', {
tagName: 'div.user-profile.widget-container',
buildKey: (attrs) => 'user-profile',
defaultState(attrs) {
return {
topic: attrs.topic,
bookmarked: attrs.topic ? attrs.topic.bookmarked : null
}
},
canInviteToForum() {
return Discourse.User.currentProp('can_invite_to_forum');
},
toggleBookmark() {
this.state.bookmarked = !this.state.bookmarked
const topicController = this.register.lookup('controller:topic')
topicController.send('toggleBookmark')
},
sendShowLogin() {
const appRoute = this.register.lookup('route:application');
appRoute.send('showLogin');
},
sendShowCreateAccount() {
const appRoute = this.register.lookup('route:application');
appRoute.send('showCreateAccount');
},
showInvite() {
const topicRoute = this.register.lookup('route:topic');
topicRoute.send('showLogin');
},
createTopic() {
const cController = this.register.lookup('controller:composer');
const dtController = this.register.lookup('controller:discovery/topics');
cController.open({
categoryId: dtController.get('category.id'),
action: Composer.CREATE_TOPIC,
draftKey: dtController.get('model.draft_key'),
draftSequence: dtController.get('model.draft_sequence')
});
},
html(attrs, state) {
const { currentUser } = this;
const topic = state.topic;
let contents = [];
var ghaza, tajrobe, hava;
const path = getOwner(this).lookup('controller:application').get('currentPath');
alert(path);
alert("state: " + JSON.stringify(state));
alert("attrs: " + JSON.stringify(attrs));
$.ajax({
url: "/categories.json",
dataType: 'json',
async: false,
success: function(data) {
for (var i = 0 ; i < data.category_list.categories.length ; i++)
{
if (data.category_list.categories[i].id == 35)
{
ghaza = data.category_list.categories[i].topic_count;
contents.push(h("a",{attributes: {href: "google.com"}},h("img.nova", {attributes: {src: "http://www.foodinsight.org/sites/default/files/styles/main_image_for_details/public/colorful%20foods_0.png",
width: "150px", height: "150px"
}})));
contents.push(h("hr"));
contents.push(h("h3",["نوآ-001: کاهش هدر رفت غذا",h("sup", ghaza + " ")]));
contents.push(h("hr"));
}
else if (data.category_list.categories[i].id == 50)
{
tajrobe = data.category_list.categories[i].topic_count;
contents.push(h("a",{attributes: {href: "google.com"}},h("img.nova", {attributes: {src: "/uploads/default/original/2X/d/d6958323043aa78b6d289e9d8921e204985a5b40.png",
width: "150px", height: "150px"
}})));
contents.push(h("hr"));
contents.push(h("h3",["نوآ-002: مستند سازی تجربه ها",h("sup", tajrobe + " ")]));
contents.push(h("hr"));
}
else if (data.category_list.categories[i].id == 30)
{
hava = data.category_list.categories[i].topic_count;
contents.push(h("a",{attributes: {href: "google.com"}},h("img.nova", {attributes: {src: "http://cpmsarl.com/wp-content/uploads/2016/08/Romania-Start-up-plus-1.jpg",
width: "150px", height: "150px"
}})));
contents.push(h("hr"));
contents.push(h("h3",["نوآ-003: مسایل اقتصادی",h("sup", hava + " ")]));
contents.push(h("hr"));
}
}
}
});
if (currentUser)
{
contents.push(this.attach("button",{
className: "btn btn-default",
label: "topic.create",
icon: "plus",
action: "createTopic"
}));
}
else
{
contents.push(this.attach('button', {
label: "sign_up",
className: 'btn-primary sign-up-button',
action: "sendShowCreateAccount"
}));
}
return h('div.widget-inner', contents);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment