2020-10-29 15:19:27 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
2020-10-29 19:02:32 +00:00
|
|
|
import QtGraphicalEffects 1.13
|
2021-10-20 09:45:38 +00:00
|
|
|
|
2021-09-28 15:04:06 +00:00
|
|
|
import utils 1.0
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared.controls 1.0
|
2021-10-20 09:45:38 +00:00
|
|
|
|
2021-11-02 10:29:51 +00:00
|
|
|
import StatusQ.Core.Theme 0.1
|
2021-10-20 09:45:38 +00:00
|
|
|
import StatusQ.Controls 0.1
|
2021-11-02 10:29:51 +00:00
|
|
|
import StatusQ.Controls.Validators 0.1
|
2021-10-20 09:45:38 +00:00
|
|
|
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared 1.0
|
|
|
|
import shared.popups 1.0
|
2021-09-30 09:43:29 +00:00
|
|
|
import "../stores"
|
2020-10-29 15:19:27 +00:00
|
|
|
|
2021-10-14 11:07:19 +00:00
|
|
|
// TODO: replace with StatusModal
|
2020-10-29 15:19:27 +00:00
|
|
|
ModalPopup {
|
2020-10-29 19:02:32 +00:00
|
|
|
property string ogUrl
|
|
|
|
property string ogName
|
|
|
|
property bool modifiyModal: false
|
2020-10-29 20:07:52 +00:00
|
|
|
property bool toolbarMode: false
|
2020-10-29 15:19:27 +00:00
|
|
|
|
|
|
|
id: popup
|
2020-10-29 20:07:52 +00:00
|
|
|
width: toolbarMode ? 345 : 480
|
2021-11-02 10:29:51 +00:00
|
|
|
height: toolbarMode ? 400 : 480
|
2020-10-29 19:02:32 +00:00
|
|
|
|
2020-10-29 20:07:52 +00:00
|
|
|
modal: !toolbarMode
|
2020-10-29 19:02:32 +00:00
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
id: bgPopup
|
|
|
|
color: Style.current.background
|
|
|
|
radius: Style.current.radius
|
|
|
|
layer.enabled: true
|
|
|
|
layer.effect: DropShadow{
|
|
|
|
width: bgPopup.width
|
|
|
|
height: bgPopup.height
|
|
|
|
x: bgPopup.x
|
|
|
|
y: bgPopup.y + 10
|
|
|
|
visible: bgPopup.visible
|
|
|
|
source: bgPopup
|
|
|
|
horizontalOffset: 0
|
|
|
|
verticalOffset: 5
|
|
|
|
radius: 10
|
|
|
|
samples: 15
|
2021-07-29 19:20:15 +00:00
|
|
|
color: Style.current.dropShadow
|
2020-10-29 19:02:32 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-29 15:19:27 +00:00
|
|
|
|
|
|
|
onOpened: {
|
2021-11-02 10:29:51 +00:00
|
|
|
urlInput.input.forceActiveFocus(Qt.MouseFocusReason)
|
2020-10-29 15:19:27 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 19:02:32 +00:00
|
|
|
onClosed: {
|
|
|
|
reset()
|
|
|
|
}
|
|
|
|
|
|
|
|
function reset() {
|
|
|
|
modifiyModal = false
|
2020-10-29 20:07:52 +00:00
|
|
|
toolbarMode = false
|
2021-11-02 10:29:51 +00:00
|
|
|
urlInput.reset()
|
|
|
|
nameInput.reset()
|
2020-10-29 19:02:32 +00:00
|
|
|
ogUrl = ""
|
|
|
|
ogName = ""
|
|
|
|
x = Math.round(((parent ? parent.width : 0) - width) / 2)
|
|
|
|
y = Math.round(((parent ? parent.height : 0) - height) / 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
title: modifiyModal ?
|
2020-10-29 20:07:52 +00:00
|
|
|
toolbarMode ?
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "Favorite added"
|
|
|
|
qsTrId("favorite-added") :
|
|
|
|
//% "Edit"
|
|
|
|
qsTrId("edit")
|
|
|
|
//% "Add favorite"
|
|
|
|
: qsTrId("add-favorite")
|
2020-10-29 15:19:27 +00:00
|
|
|
|
|
|
|
Column {
|
|
|
|
width: parent.width
|
|
|
|
spacing: Style.current.padding
|
|
|
|
|
2021-11-02 10:29:51 +00:00
|
|
|
StatusInput {
|
2020-10-29 15:19:27 +00:00
|
|
|
id: urlInput
|
2021-11-02 10:29:51 +00:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
leftPadding: 0
|
|
|
|
rightPadding: 0
|
|
|
|
label: qsTr("URL")
|
|
|
|
input.text: popup.ogurl
|
|
|
|
input.placeholderText: qsTr("Paste URL")
|
|
|
|
input.component: StatusButton {
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
border.width: 1
|
|
|
|
border.color: Theme.palette.primaryColor1
|
|
|
|
size: StatusBaseButton.Size.Tiny
|
|
|
|
text: qsTr("Paste")
|
|
|
|
onClicked: {
|
|
|
|
text = qsTr("Pasted")
|
|
|
|
urlInput.input.edit.paste()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
validators: [
|
|
|
|
StatusUrlValidator {
|
|
|
|
errorMessage: qsTr("Please enter a valid URL")
|
|
|
|
}
|
|
|
|
]
|
2020-10-29 15:19:27 +00:00
|
|
|
}
|
|
|
|
|
2021-11-02 10:29:51 +00:00
|
|
|
StatusInput {
|
2020-10-29 15:19:27 +00:00
|
|
|
id: nameInput
|
2021-11-02 10:29:51 +00:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
leftPadding: 0
|
|
|
|
rightPadding: 0
|
|
|
|
label: qsTr("Name")
|
|
|
|
input.text: popup.ogurl
|
|
|
|
input.placeholderText: qsTr("Name of the website")
|
|
|
|
validators: [
|
|
|
|
StatusMinLengthValidator {
|
|
|
|
errorMessage: qsTr("Please enter a name")
|
|
|
|
minLength: 1
|
|
|
|
}
|
|
|
|
]
|
2020-10-29 15:19:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-29 19:02:32 +00:00
|
|
|
footer: Item {
|
|
|
|
width: parent.width
|
2021-01-13 19:15:52 +00:00
|
|
|
height: removeBtn.height
|
2020-10-29 19:02:32 +00:00
|
|
|
|
|
|
|
StatusButton {
|
|
|
|
id: removeBtn
|
|
|
|
anchors.right: addBtn.left
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
visible: popup.modifiyModal
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "Remove"
|
|
|
|
text: qsTrId("remove")
|
2020-10-29 19:02:32 +00:00
|
|
|
anchors.bottom: parent.bottom
|
2021-10-20 09:45:38 +00:00
|
|
|
type: StatusBaseButton.Type.Danger
|
2020-10-29 19:02:32 +00:00
|
|
|
onClicked: {
|
2021-10-14 14:29:33 +00:00
|
|
|
BookmarksStore.deleteBookmark(popup.ogUrl)
|
2020-10-29 19:02:32 +00:00
|
|
|
popup.close()
|
2020-10-29 15:19:27 +00:00
|
|
|
}
|
2020-10-29 19:02:32 +00:00
|
|
|
}
|
2020-10-29 15:19:27 +00:00
|
|
|
|
2020-10-29 19:02:32 +00:00
|
|
|
StatusButton {
|
|
|
|
id: addBtn
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.smallPadding
|
|
|
|
text: popup.modifiyModal ?
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "Done"
|
|
|
|
qsTrId("done") :
|
|
|
|
//% "Add"
|
|
|
|
qsTrId("add")
|
2020-10-29 19:02:32 +00:00
|
|
|
anchors.bottom: parent.bottom
|
2021-11-02 10:29:51 +00:00
|
|
|
enabled: nameInput.valid && urlInput.valid
|
2020-10-29 19:02:32 +00:00
|
|
|
onClicked: {
|
|
|
|
if (!popup.modifiyModal) {
|
2021-08-17 17:03:03 +00:00
|
|
|
// remove "add favorite" button at the end, add new bookmark, add "add favorite" button back
|
2021-10-14 14:29:33 +00:00
|
|
|
BookmarksStore.deleteBookmark("")
|
2021-11-02 10:29:51 +00:00
|
|
|
BookmarksStore.addBookmark(urlInput.input.text, nameInput.input.text)
|
2021-09-30 09:43:29 +00:00
|
|
|
BookmarksStore.addBookmark("", qsTr("Add Favorite"))
|
2021-11-02 10:29:51 +00:00
|
|
|
} else if (popup.ogName !== nameInput.input.text || popup.ogUrl !== urlInput.input.text) {
|
|
|
|
BookmarksStore.updateBookmark(popup.ogUrl, urlInput.input.text, nameInput.input.text)
|
2020-10-29 19:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
popup.close()
|
|
|
|
}
|
2020-10-29 15:19:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|