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
|
enyo.kind({
name: "biblez.notes",
kind: "enyo.FittableRows",
fit: true,
events: {
onBack: "",
onChange: ""
},
published: {
osisRef: null,
noteId: null,
noteText: ""
},
components: [
{name: "messagePopup", kind: "onyx.Popup", scrim: true, centered: true, floating: true, classes: "message-popup"},
{kind: "onyx.MoreToolbar", components: [
{kind: "onyx.IconButton", src: "assets/back.png", ontap: "handleBack"},
{name: "label", content: $L("Notes")}
]},
{kind: "enyo.Scroller", touch: true, fit: true, style: "text-align: center;", components: [
{kind: "onyx.InputDecorator", style: "margin: 10px;", alwaysLooksFocused: true, components: [
{name: "noteInput", kind: "onyx.RichText", classes: "note-input", placeholder: "Enter your note here", allowHmtl: false}
]},
{tag: "br"},
{name: "btDelete", kind: "onyx.Button", content: $L("Delete Note"), disabled: true, classes: "onyx-negative", style: "margin: 10px;", ontap: "removeNote"}
]}
],
rendered: function () {
this.inherited(arguments);
this.$.noteInput.applyStyle("width", window.innerWidth > 700 ? 600 + "px" : window.innerWidth-40 + "px");
},
setFocus: function () {
//this.$.noteInput.focus();
},
osisRefChanged: function (inSender, inEvent) {
this.$.noteInput.setValue("");
this.$.label.setContent($L("Notes for") + " " + api.formatOsis(this.osisRef));
},
noteIdChanged: function () {
if (this.noteId !== null) {
api.getNote(this.noteId, enyo.bind(this, function (inError, inNote) {
if(!inError) {
this.$.noteInput.setValue(inNote.text);
this.$.btDelete.setDisabled(false);
} else
this.handleError(inError);
}));
} else {
this.$.btDelete.setDisabled(true);
}
},
updateNote: function (inSender, inEvent) {
api.putNote({id: this.noteId, text: this.$.noteInput.getValue().replace(/"/g, '"'), osisRef: this.osisRef}, enyo.bind(this, function (inError, inId) {
if(!inError) {
this.doChange({action: "update", osisRef: this.osisRef});
this.doBack();
} else
console.log(inError);
}));
},
removeNote: function () {
api.removeNote({id: this.noteId, osisRef: this.osisRef}, enyo.bind(this, function (inError) {
if(!inError) {
this.doChange({action: "remove", osisRef: this.osisRef});
} else
this.handleError(inError);
}));
},
handleBack: function() {
if(this.$.noteInput.getValue() !== "") {
this.updateNote();
this.$.noteInput.setValue(" ");
}
this.doBack();
},
handleError: function (inMessage) {
if (inMessage.message)
inMessage = inMessage.message;
this.$.messagePopup.setContent(inMessage);
this.$.messagePopup.show();
}
});
|