1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
const Endless = imports.gi.Endless;
const GObject = imports.gi.GObject;
const Lang = imports.lang;
GObject.ParamFlags.READWRITE = GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE;
const CategoryModel = new Lang.Class({
Name: "CategoryModel",
Extends: GObject.Object,
Properties: {
/**
* Property: id
* String for referring to this category internally
*
* Can generally be equal to <CategoryModel.title>, though that is not
* required.
*/
'id': GObject.ParamSpec.string('id', 'ID string',
'String for referring to this category internally',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
''),
'description': GObject.ParamSpec.string('description', 'Category Description', 'This is the text that the user reads on the category page.',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
""),
'title': GObject.ParamSpec.string('title', 'Category Name', 'This is the name that is displayed on the front page and as the title on the category page.',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
""),
'image-uri': GObject.ParamSpec.string('image-uri', 'Category Image URI', 'Path to image for this category in the GResource',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
""),
'image-thumbnail-uri': GObject.ParamSpec.string('image-thumbnail-uri', 'Category Thumbnail Image URI', 'Path to thumbnail image for this category in the GResource',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
""),
'is-main-category': GObject.ParamSpec.boolean('is-main-category', 'Is Main Category boolean', 'Flag denoting whether this category is the main category for this app',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
false),
/**
* Property: has_articles
* Whether this category contains articles
*
* This property is not computed in any way, but is set by the library
* model when loading from a JSON file.
* This value is used to determine whether a category should be
* clickable, for example.
*/
'has-articles': GObject.ParamSpec.boolean('has-articles',
'Has articles',
'Indicates whether category has any articles under it',
GObject.ParamFlags.READWRITE,
false)
},
_init: function(params) {
this._subcategories = {};
this.parent(params);
},
/**
* Method: addSubcategory
* Add a subcategory to this model
*
* Parameters:
* modelObj - another <CategoryModel> that is to be a subcategory of this
* one.
*
* Does nothing if this category already has a subcategory with _modelObj_'s
* ID.
*/
addSubcategory: function (modelObj) {
if (!this._subcategories.hasOwnProperty(modelObj.id)) {
this._subcategories[modelObj.id] = modelObj;
}
},
/**
* Method: getSubcategories
* List this model's subcategories
*
* Returns:
* An array of <CategoryModels> representing this category's
* subcategories, or an empty array if there are none.
*/
getSubcategories: function () {
let retval = [];
for (let id in this._subcategories) {
retval.push(this._subcategories[id]);
}
return retval;
}
});
/**
* Function: newFromJson
* Construct a new <CategoryModel> from data exported by the CMS
*
* Parameters:
* json - a category object created by parsing the JSON file
*
* Returns:
* A newly created <CategoryModel> with no subcategories.
*
* See <DomainWikiModel.loadFromJson> for the structure of the JSON object.
*/
function newFromJson(json) {
let retval = new CategoryModel({
id: json['category_name'],
description: json['content_text'],
title: json['category_name'],
image_uri: json['image_file'],
image_thumbnail_uri: json['image_thumb_uri'],
is_main_category: json['is_main_category']
});
return retval;
}
|