this.previewIntro = response.body.item.intro_text;
this.item.primary_topic = response.body.item.topic;
this.item.url = response.body.item.url;
+ this.item.dept = response.body.item.dept;
this.updatePrimaryTopicIconURL();
this.mode = "preview";
this.updatePrimaryTopicIconURL();
}
- function _loadItem(vm, callback) {
+ function _startEdit(c) {
+ _loadItem(c, () => { _initEditor(c); });
+ }
+
+ function _loadItem(c, callback) {
if (!page) { return callback(); }
if (page.contentType == "journal") {
newslash.getJournal(page.id).then(
(resp) => {
for (k in resp.journal) {
- vm.item[k] = resp.journal[k];
+ c.item[k] = resp.journal[k];
}
callback();
},
return callback();
}
- function _startEdit(vm) {
- _loadItem(vm, () => { _initEditor(vm); });
- }
-
- function _initEditor(vm) {
+ function _initEditor(c) {
// backup original item
- // copy item property to vm
- vm.originalItem = {};
- for (k in vm.$data.item) {
- if (vm.item[k]) {
- vm.originalItem[k] = vm.item[k];
+ // copy item property to c (component)
+ c.originalItem = {};
+ for (k in c.$data.item) {
+ if (c.item[k]) {
+ c.originalItem[k] = c.item[k];
}
}
// set createtime
- if (vm.item.createtime) {
- var dt = nsUtil.decodeMySQLDateTime(vm.item.createtime);
- vm.editor.createtime = nsUtil.formatToLocalISOString(dt);
+ if (c.item.createtime) {
+ var dt = nsUtil.decodeMySQLDateTime(c.item.createtime);
+ c.editor.createtime = nsUtil.formatToLocalISOString(dt);
} else {
- vm.editor.createtime = nsUtil.formatToLocalISOString(new Date());
+ c.editor.createtime = nsUtil.formatToLocalISOString(new Date());
}
- vm.editor.author = user.nickname;
+ c.editor.author = user.nickname;
- if (vm.item.tags) {
- var tagnames = vm.item.tags.map(x => {return x.tagname});
- vm.editor.tags_string = tagnames.join(" ");
+ if (c.item.tags) {
+ var tagnames = c.item.tags.map(x => {return x.tagname});
+ c.editor.tags_string = tagnames.join(" ");
}
- updateTopics.call(vm);
+ updateTopics.call(c);
// journal edit mode
if (page.type == 'journal' && page.id) {
- vm.cancelable = 1;
- vm.editor.title = vm.item.title;
- vm.editor.intro_text = vm.item.article;
- vm.editor.tags_string = vm.item.tags_string || "";
- vm.editor.comment_status = vm.item.comment_status;
- vm.editor.formatter = vm.item.formatter;
- vm.editor.posttype = vm.item.posttype;
- vm.editor.id = vm.item.id;
+ c.cancelable = 1;
+ c.editor.title = c.item.title;
+ c.editor.intro_text = c.item.article;
+ c.editor.tags_string = c.item.tags_string || "";
+ c.editor.comment_status = c.item.comment_status;
+ c.editor.formatter = c.item.formatter;
+ c.editor.posttype = c.item.posttype;
+ c.editor.id = c.item.id;
}
// story edit mode
if (page.type == 'story' && page.stoid) {
- vm.cancelable = 1;
+ c.cancelable = 1;
+ c.item.content_type = "story";
- vm.$newslash.getStoryByID(page.stoid,
+ c.$newslash.getStoryByID(page.stoid,
(resp) => { // succeed
for (k in resp.body.item) {
- vm.editor.item[k] = resp.body.item[k];
+ c.editor.item[k] = resp.body.item[k];
}
},
(resp) => { //failed
- vm.message = resp.body.message;
+ c.message = resp.body.message;
});
}
// submission to story mode
- if (vm.item.submission_id) {
- vm.$newslash.getSubmissionByID(vm.item.submission_id,
+ if (c.item.submission_id) {
+ c.$newslash.getSubmissionByID(c.item.submission_id,
(resp) => { // succeed
- vm.editor.title = resp.body.item.title;
- vm.editor.intro_text = resp.body.item.drafttext;
+ c.editor.title = resp.body.item.title;
+ c.editor.intro_text = resp.body.item.drafttext;
+ c.item.content_type = "story";
},
(resp) => { //failed
- vm.message = resp.body.message;
+ c.message = resp.body.message;
});
}
// check formatter
- if (vm.editor.formatter == "legacy") {
- vm.enableAutoPreview = 0;
+ if (c.editor.formatter == "legacy") {
+ c.enableAutoPreview = 0;
}
- vm.mode = "editing";
+ c.mode = "editing";
}
/*
};
+/*
+ * utilities
+ */
+
articleItem.run = function (params) {
params = params || {};
if (!params.el) {