forked from Randolio/randol_notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcl_notes.lua
More file actions
162 lines (157 loc) · 5.59 KB
/
cl_notes.lua
File metadata and controls
162 lines (157 loc) · 5.59 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
local function CloseNotepad()
ToggleAnimation(false)
lib.hideContext()
end
local function ManageNote(data, noteid)
local manageNotes = "manage_notes"
local notes_manage = {
id = manageNotes,
canClose = false,
title = "Manage Notes",
options = {
{
title = "Delete Note",
description = "Delete note #"..data.id,
icon = "fa-solid fa-trash",
onSelect = function()
TriggerServerEvent('randol_notes:server:deleteNote', data, noteid)
CloseNotepad()
end,
},
{
title = "Rip Out Note",
description = "Rip out note #"..data.id.." and give to someone.",
icon = "fa-solid fa-trash",
onSelect = function()
TriggerServerEvent('randol_notes:server:ripNote', data, noteid)
CloseNotepad()
end,
},
{
title = "Close",
icon = "fa-solid fa-xmark",
onSelect = function()
CloseNotepad()
end,
},
}
}
lib.registerContext(notes_manage)
lib.showContext(manageNotes)
end
local function NotepadTask(task, noteid)
if task == 'view' then
local data = lib.callback.await('randol_notes:server:getNotes', false, noteid)
if data then
local viewNotes = {}
for i=1, #data do
local v = data[i]
local test = v.text
if string.len(v.text) > 10 then test = string.sub(v.text, 1, 10) .. ".." end
local signed = (v.signed and 'Signed') or 'Unsigned'
viewNotes[#viewNotes+1] = {
title = test,
description = ""..v.date.." ["..signed.."]",
icon = "fa-solid fa-note-sticky",
onSelect = function()
ManageNote(v, noteid)
end,
metadata = {
{label = 'Note', value = v.text},
},
}
end
viewNotes[#viewNotes+1] = {
title = "Close",
icon = "fa-solid fa-xmark",
onSelect = function()
CloseNotepad()
end,
}
lib.registerContext({ id = 'noteMenu2', title = "Saved Notes", canClose = false, options = viewNotes })
lib.showContext('noteMenu2')
else
CloseNotepad()
QBCore.Functions.Notify('You don\'t have any notes saved.', 'error')
return
end
elseif task == 'new' then
local input = lib.inputDialog("New Note", {
{
type = "textarea",
label = "Write your message below.",
required = true,
placeholder = "Met up with all the homies today and kissed them at the park. Spicy."
},
{type = 'checkbox', label = 'Sign the note?'},
})
if not input then ToggleAnimation(false) return end
local message = input[1]
local signed = input[2]
TriggerServerEvent('randol_notes:server:newNote', message, signed, noteid)
ToggleAnimation(false)
elseif task == 'newtorn' then
local input = lib.inputDialog("Create Torn Note", {
{
type = "textarea",
label = "Write your message below.",
required = true,
placeholder = "Met up with all the homies today and kissed them at the park. Spicy."
},
{type = 'checkbox', label = 'Sign the note?'},
})
if not input then ToggleAnimation(false) return end
local message = input[1]
local signed = input[2]
TriggerServerEvent('randol_notes:server:newTornNote', message, signed)
ToggleAnimation(false)
end
end
local function OpenNotepad(noteid)
ToggleAnimation(true)
local some_id = "notepadinit"
local notepadMenu = {
id = some_id,
canClose = false,
title = "Notebook",
options = {
{
title = "My Notes",
description = "View my notes.",
icon = "fa-solid fa-note-sticky",
onSelect = function()
NotepadTask('view', noteid)
end,
},
{
title = "New Note",
description = "Write a new note to save.",
icon = "fa-solid fa-pencil",
onSelect = function()
NotepadTask('new', noteid)
end,
},
{
title = "New Note (Torn)",
description = "Write a new note to tear out straight away",
icon = "fa-solid fa-pencil",
onSelect = function()
NotepadTask('newtorn')
end,
},
{
title = "Close",
icon = "fa-solid fa-xmark",
onSelect = function()
CloseNotepad()
end,
},
}
}
lib.registerContext(notepadMenu)
lib.showContext(some_id)
end
RegisterNetEvent("randol_notes:client:useItem", function(noteid)
if GetInvokingResource() then return end
OpenNotepad(noteid)
end)