Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 9.56 KB | None | 0 0
  1. import QtQuick 2.11
  2. import QtQuick.Layouts 1.1
  3. import Shared 1.0
  4.  
  5. import "controls"
  6. import "delegates"
  7.  
  8. SharedStackPage {
  9.     id: participationDialog
  10.  
  11.     property ClubTournamentController tc: tournamentController
  12.  
  13.     pageUrl: "participation-dialog"
  14.     pageTitle: qsTr("Participate in this tournament")
  15.  
  16.     onPlayerReady: {
  17.         tc.addedPlayers.append({
  18.                                    "_player": playerAdder.playerModel
  19.                                });
  20.     }
  21.  
  22.     sourceComponent: StackPageContent {
  23.         readonly property bool teamFull: (!tc.teamCompetition
  24.                                           || tc.addedPlayers.count === tc.teamSize)
  25.         Connections {
  26.             enabled: visible
  27.             target: tournamentController
  28.             onParticipationSuccess: {
  29.                 stackView.pop();
  30.             }
  31.         }
  32.  
  33.         onPageActivating: {
  34.             acceptCheckBox.checked = false;
  35.             switch (tc.paymentOption) {
  36.             case controller.paymentOptionVoluntary:
  37.                 footer.infoText = qsTr("Continue to select payment.");
  38.                 footer.confirmButtonText = qsTr("Continue");
  39.                 break;
  40.             case controller.paymentOptionDisabled:
  41.                 footer.infoText = qsTr("Fee will be paid at the club.");
  42.                 footer.confirmButtonText = qsTr("Enroll");
  43.                 break;
  44.             case controller.paymentOptionRequired:
  45.                 footer.infoText = qsTr("Payment required.");
  46.                 footer.confirmButtonText = qsTr("Continue to pay");
  47.                 break;
  48.             default:
  49.                 debug.log("Warning: invalid paymentoption");
  50.                 return "";
  51.             }
  52.         }
  53.  
  54.         onPageDeactivated: {
  55.             organizerText.text = "";
  56.             teamNameInput.text = "";
  57.         }
  58.  
  59.         SharedFlickable {
  60.             anchors.fill: parent
  61.  
  62.             contentHeight: contentColumn.height + theme.textMargins
  63.             interactive: contentHeight > height
  64.  
  65.             Column {
  66.                 id: contentColumn
  67.                 width: parent.width
  68.                 spacing: 20 * scaleFactor
  69.                 anchors.left: parent.left
  70.                 anchors.right: parent.right
  71.                 anchors.margins: theme.textMargins
  72.  
  73.                 // Hidden automatically if there is only one series available
  74.                 StyledText {
  75.                     width: parent.width
  76.                     visible: tc.seriesModel.length > 1
  77.                     text: qsTr("* Select series")
  78.                     font.pixelSize: theme.smallFontSize
  79.                 }
  80.  
  81.                 FlatButton {
  82.                     width: parent.width
  83.                     visible: tc.seriesModel.length > 1
  84.                     buttonModel: tc.seriesModel
  85.                     onSelectedValueChanged: {
  86.                         tc.selectedSeries = selectedValue;
  87.                         tc.updatePrice();
  88.                     }
  89.                 }
  90.  
  91.                 StyledText {
  92.                     width: parent.width
  93.                     visible: !tc.startTimeWishDisabled
  94.                     text: qsTr("Select preferred starting time")
  95.                     font.pixelSize: theme.smallFontSize
  96.                 }
  97.  
  98.                 FlatButton {
  99.                     width: parent.width
  100.                     visible: !tc.startTimeWishDisabled
  101.                     buttonModel: [{
  102.                             "title": qsTr("No Preference"),
  103.                             "value": 0
  104.                         }, {
  105.                             "title": qsTr("Early"),
  106.                             "value": 1
  107.                         }, {
  108.                             "title": qsTr("Late"),
  109.                             "value": 2
  110.                         }]
  111.                     onSelectedValueChanged: tc.timeHint = selectedValue
  112.                 }
  113.  
  114.                 StyledText {
  115.                     width: parent.width
  116.                     visible: tc.teamCompetition && tc.teamNamingEnabled === true
  117.                     text: qsTr("Team name")
  118.                     font.pixelSize: theme.smallFontSize
  119.                 }
  120.  
  121.                 FlatInput {
  122.                     id: teamNameInput
  123.                     width: parent.width
  124.                     visible: tc.teamNamingEnabled === true
  125.                     onTextChanged: tc.teamName = text
  126.                 }
  127.  
  128.                 StyledText {
  129.                     width: parent.width
  130.                     text: qsTr("Message to organizers")
  131.                     font.pixelSize: theme.smallFontSize
  132.                     visible: !tc.hideOptionalMessage
  133.                 }
  134.  
  135.                 FlatTextArea {
  136.                     width: parent.width
  137.                     id: organizerText
  138.                     visible: !tc.hideOptionalMessage
  139.                     onTextChanged: {
  140.                         tc.note = text;
  141.                     }
  142.                 }
  143.  
  144.                 StyledText {
  145.                     font.pixelSize: theme.smallFontSize
  146.                     text: qsTr("Add team participants %1 / %2").arg(tc.addedPlayers.count).arg(
  147.                               tc.teamSize)
  148.                     visible: tc.teamCompetition
  149.                 }
  150.  
  151.                 Column {
  152.                     width: parent.width
  153.                     anchors.left: parent.left
  154.                     anchors.right: parent.right
  155.                     anchors.margins: -theme.textMargins
  156.                     visible: tc.teamCompetition
  157.  
  158.                     AppMenuSeparator {
  159.                         z: 1
  160.                     }
  161.  
  162.                     Repeater {
  163.                         model: tc.addedPlayers
  164.                         PlayerAdderDelegate {
  165.                             clickIgnored: true
  166.                             alreadyIncluded: false
  167.                             SharedButton {
  168.                                 visible: index > 0
  169.                                 anchors.right: parent.right
  170.                                 anchors.verticalCenter: parent.verticalCenter
  171.                                 color: theme.redColor
  172.                                 labelColor: "white"
  173.                                 radius: height / 2
  174.                                 width: height
  175.                                 onClicked: tc.addedPlayers.remove(index)
  176.                                 StyledImage {
  177.                                     color: "white"
  178.                                     colorize: true
  179.                                     source: "qrc:/images/icon_close.png"
  180.                                     width: parent.height / 3.0
  181.                                     height: width
  182.                                     anchors.centerIn: parent
  183.                                 }
  184.                             }
  185.                         }
  186.                     }
  187.                 }
  188.  
  189.                 SharedButton {
  190.                     width: parent.width
  191.                     text: qsTr("Add player")
  192.  
  193.                     function filterAddedPlayers(id, clubId) {
  194.                         if (clubId !== session.clubNumber) {
  195.                             return true;
  196.                         }
  197.  
  198.                         for (var i in tc.competition.participants) {
  199.                             if (tc.competition.participants[i].number === id) {
  200.                                 return true;
  201.                             }
  202.                         }
  203.  
  204.                         for (i = 0; i < tc.addedPlayers.count; ++i) {
  205.                             if (tc.addedPlayers.get(i)._player.id === id) {
  206.                                 return true;
  207.                             }
  208.                         }
  209.  
  210.                         return false;
  211.                     }
  212.  
  213.                     onClicked: {
  214.                         playerAdder.allowManualPlayers = false;
  215.                         playerAdder.hideOtherClubs = true;
  216.                         playerAdder.setPlayerFilter(filterAddedPlayers);
  217.                         playerAdder.show();
  218.                     }
  219.                     visible: (tc.teamCompetition && tc.addedPlayers.count < tc.teamSize)
  220.                 }
  221.  
  222.                 Item {
  223.                     width: 1
  224.                     height: 1
  225.                 }
  226.  
  227.                 CustomCheckBox {
  228.                     id: acceptCheckBox
  229.                     width: parent.width
  230.                     text: qsTr("I accept the terms, enrollment obligatory and tournament fees regarding this tournaments participation.")
  231.                     onCheckedChanged: footer.enabled = checked
  232.                 }
  233.  
  234.                 Item {
  235.                     width: 1
  236.                     height: footer.height
  237.                 }
  238.             }
  239.         }
  240.  
  241.         SharedConfirmationFooter {
  242.             id: footer
  243.             priceLabelText: tc.price
  244.             anchors.bottom: parent.bottom
  245.             priceLabelColor: theme.inverted ? theme.darkSkyBlue : theme.yellowColor
  246.             labelsVisible: true
  247.             optionVisible: false
  248.             confirmationEnabled: acceptCheckBox.checked && teamFull
  249.             headerText: qsTr("Total price")
  250.  
  251.             onAccepted: {
  252.                 if (tc.paymentOption !== controller.paymentOptionDisabled) {
  253.                     stackView.push({
  254.                                        "item": pages.clubTournamentsConfirmPayment,
  255.                                        "immediate": false
  256.                                    });
  257.                 }
  258.                 else {
  259.                     tc.requestPayOnJoined = false;
  260.                     tc.performJoin();
  261.                 }
  262.             }
  263.         }
  264.     }
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement