1 | define([ |
---|
2 | "../../widgets/TabbedBrowser", |
---|
3 | "../classes/categories", |
---|
4 | "../classes/questions", |
---|
5 | "../classes/topics", |
---|
6 | "dojo/_base/array", |
---|
7 | "dojo/_base/declare", |
---|
8 | "dojo/_base/lang" |
---|
9 | ], function(TabbedBrowser, categories, questions, topics, array, declare, lang) { |
---|
10 | return declare([TabbedBrowser],{ |
---|
11 | tabPosition: 'left-h', |
---|
12 | include: null, |
---|
13 | dndType: "question", |
---|
14 | getCategories: function(){ |
---|
15 | return categories.query(); |
---|
16 | }, |
---|
17 | getCategoryName: function(category){ return category.name; }, |
---|
18 | getCategoryCount: function(category){ return category.count; }, |
---|
19 | getTopics: function(category) { |
---|
20 | return topics.query({category:category.name}); |
---|
21 | }, |
---|
22 | getTopicName: function(topic){ return topic.name; }, |
---|
23 | getTopicCount: function(topic){ return topic.count; }, |
---|
24 | getItems: function(category,topic) { |
---|
25 | return questions.query({category:category.name,topic:topic.name}) |
---|
26 | .then(lang.hitch(this,function(items){ |
---|
27 | return array.filter(items, function(item){ |
---|
28 | return (this.include === 'published' && item.publicationDate) || |
---|
29 | (this.include === 'drafts' && !item.publicationDate) || |
---|
30 | true; |
---|
31 | }, this); |
---|
32 | })); |
---|
33 | }, |
---|
34 | getItemName: function(item) { |
---|
35 | var title = '['+item.code+']'+item.title; |
---|
36 | if ( !this.include ) { |
---|
37 | title += (item.publicationDate ?' (published on '+item.publicationDate+')':' (unpublished)'); |
---|
38 | } |
---|
39 | return title; |
---|
40 | }, |
---|
41 | areItemsEqual: function(i1,i2) { |
---|
42 | return questions.getId(i1) === questions.getId(i2); |
---|
43 | } |
---|
44 | }); |
---|
45 | }); |
---|