Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 2.11
- import Shared 1.0
- import "controls"
- import "delegates"
- SharedStackPage {
- id: buddiesPage
- property int buttonWidth: (width - 4 * theme.textMargins) / 3
- property var model: controller.buddyList.sortedBuddyModel
- property bool refreshWhenActivated: true
- readonly property JsonRequester invites: controller.pendingInvites
- readonly property JsonRequester requests: controller.buddyInvites
- function fetchBuddyLists() {
- invites.request();
- requests.request();
- controller.buddyList.request();
- }
- headerTitle: qsTr("Buddies")
- pageUrl: "buddies"
- onPageActivated: {
- if (refreshWhenActivated) {
- fetchBuddyLists();
- if (!model) {
- model = Qt.binding(function () {
- return controller.buddyList.model;
- });
- }
- refreshWhenActivated = false;
- }
- }
- onHeaderClicked: {
- fetchBuddyLists();
- }
- JsonRequester {
- id: buddyInviteRequester
- method: "POST"
- path: "/buddy/invitation?token=" + token
- onSuccess: invites.request()
- onFail: notifyError(error, qsTr("Failed to invite buddy"))
- }
- JsonRequester {
- id: deleteBuddyInvitation
- method: "DELETE"
- onFail: confirmError(error, qsTr("Failed to remove buddy"))
- onSuccess: invites.request()
- }
- JsonRequester {
- id: handleInvite
- method: "PUT"
- onSuccess: {
- requests.request();
- controller.buddyList.request();
- }
- }
- onPlayerReady: {
- var playerNumber = playerAdder.playerNumber, clubNumber = playerAdder.clubNumber;
- var data = [{
- "number": playerNumber,
- "club": {
- "number": clubNumber
- }
- }];
- buddyInviteRequester.request(data);
- }
- function canAddBuddy(number, clubnumber) {
- var pending = invites.model;
- for (var a in pending) {
- var buddy = pending[a];
- if (number === buddy.number && clubnumber === buddy.club.number) {
- return true;
- }
- }
- var buddies = controller.buddyList.model;
- for (a in buddies) {
- buddy = buddies[a];
- if (number === buddy.number && clubnumber === buddy.club.number) {
- return true;
- }
- }
- if (number === session.playerNumber && clubnumber === session.clubNumber) {
- return true;
- }
- return false;
- }
- sourceComponent: SharedFlickable {
- id: flickArea
- anchors.fill: parent
- contentHeight: column.height + theme.textMargins
- pullToRefresh: true
- onRefreshEvent: fetchBuddyLists()
- Column {
- id: column
- width: parent.width
- anchors.margins: theme.textMargins
- anchors.left: parent.left
- anchors.right: parent.right
- spacing: 20 * scaleFactor
- SharedButton {
- id: searchAndAddButton
- width: parent.width
- text: qsTr("Add buddy")
- labelColor: theme.accentForeground
- onClicked: {
- playerAdder.title = qsTr("Add buddy");
- playerAdder.setPlayerFilter(canAddBuddy);
- playerAdder.showBuddies = false;
- playerAdder.show();
- }
- }
- Item {
- width: parent.width
- height: requests.model.length ? pendingRequests.height : 0
- Behavior on height {
- NumberAnimation {
- easing.type: Easing.OutSine
- }
- }
- Column {
- id: pendingRequests
- width: parent.width
- spacing: 10 * scaleFactor
- SectionHeader {
- text: qsTr("Requests")
- height: pendingRequests.height
- && pendingRequests.model.length ? implicitHeight : 0
- Behavior on height {
- NumberAnimation {
- easing.type: Easing.OutSine
- }
- }
- Behavior on opacity {
- OpacityAnimator {
- duration: 100
- }
- }
- opacity: requests.model.length > 0 ? 1 : 0
- }
- Repeater {
- model: requests.model
- Item {
- width: parent ? parent.width : 100
- height: 190 * scaleFactor
- StyledText {
- id: header
- text: qsTr("Buddy request from ") + modelData.firstName + ' ' + modelData.lastName
- anchors.left: parent.left
- anchors.top: parent.top
- anchors.margins: 16 * scaleFactor
- anchors.right: parent.right
- }
- StyledText {
- text: modelData.club.name
- anchors.left: parent.left
- anchors.top: header.bottom
- font.pixelSize: 24 * scaleFactor
- color: theme.borderColor
- anchors.margins: 14 * scaleFactor
- wrapMode: Text.WrapAtWordBoundaryOrAnywhere
- }
- RectButton {
- id: acceptButton
- anchors.left: parent.left
- anchors.bottom: parent.bottom
- anchors.margins: 14 * scaleFactor
- text: qsTr("Accept")
- foregroundColor: theme.accentForeground
- border.color: Qt.darker(color)
- checkable: false
- color: Qt.darker(theme.accentColor, pressed ? 1.2 : 1.0)
- onClicked: {
- handleInvite.path = "/buddy/invitation?token=" + session.token + "&accept=true";
- handleInvite.request(modelData);
- }
- }
- RectButton {
- anchors.right: parent.right
- anchors.bottom: parent.bottom
- anchors.margins: 14 * scaleFactor
- text: qsTr("Decline")
- checkable: false
- color: theme.buttonColor
- onClicked: {
- handleInvite.path = "/buddy/invitation?token=" + session.token + "&accept=false";
- handleInvite.request(modelData);
- }
- }
- }
- }
- }
- }
- Item {
- width: parent.width
- height: invites.model.length ? pendingInvites.height : 0
- Behavior on height {
- NumberAnimation {
- easing.type: Easing.OutSine
- }
- }
- Column {
- id: pendingInvites
- width: parent.width
- spacing: 20 * scaleFactor
- SectionHeader {
- text: qsTr("Pending invitations")
- height: invites.model && invites.model.length ? implicitHeight : 0
- Behavior on height {
- NumberAnimation {
- easing.type: Easing.OutSine
- }
- }
- Behavior on opacity {
- OpacityAnimator {
- duration: 100
- }
- }
- opacity: invites.model.length > 0 ? 1 : 0
- }
- Repeater {
- model: invites.model
- Item {
- width: parent ? parent.width : 100
- height: 90 * scaleFactor
- Column {
- anchors.left: parent.left
- anchors.right: cancelButton.left
- anchors.margins: 16 * scaleFactor
- spacing: 4 * scaleFactor
- anchors.verticalCenter: parent.verticalCenter
- StyledText {
- id: header2
- anchors.left: parent.left
- text: modelData.firstName + ' ' + modelData.lastName + qsTr(
- " invited")
- width: parent.width
- anchors.margins: 10 * scaleFactor
- wrapMode: Text.WrapAtWordBoundaryOrAnywhere
- }
- StyledText {
- text: modelData.club.name
- width: parent.width
- anchors.left: parent.left
- font.pixelSize: 24 * scaleFactor
- color: theme.borderColor
- anchors.margins: 14 * scaleFactor
- }
- }
- RectButton {
- id: cancelButton
- anchors.right: parent.right
- anchors.margins: 10 * scaleFactor
- text: qsTr("Cancel")
- color: theme.buttonColor
- anchors.verticalCenter: parent.verticalCenter
- anchors.verticalCenterOffset: -4 * scaleFactor
- checkable: false
- onClicked: {
- deleteBuddyInvitation.path = "/buddy/" + modelData.id + "?token=" + session.token;
- deleteBuddyInvitation.request();
- }
- }
- }
- }
- }
- }
- Item {
- height: 10 * scaleFactor
- width: 1
- }
- HeaderText {
- text: qsTr("Buddies")
- visible: controller.buddyList.model.length
- }
- Item {
- height: 20 * scaleFactor
- width: 1
- }
- Grid {
- id: grid
- anchors.left: parent.left
- anchors.right: parent.right
- columns: 2
- rowSpacing: 52 * scaleFactor
- columnSpacing: 20 * scaleFactor
- Repeater {
- model: buddiesPage.model
- BuddyDelegate {
- width: parent ? grid.width / 2 - 10 * scaleFactor : 0
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement