~snwh/sudoku-app/new-icons

« back to all changes in this revision

Viewing changes to components/ManageProfileDialog.qml

  • Committer: dinko.metalac at gmail
  • Date: 2013-07-09 09:54:46 UTC
  • mfrom: (62.2.4 profiles)
  • Revision ID: dinko.metalac@gmail.com-20130709095446-u9smezoot4td0kxd
MergedĀ lp:~fredoust/sudoku-app/profiles

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.0
 
2
import Ubuntu.Components 0.1
 
3
import Ubuntu.Components.Popups 0.1
 
4
import "../js/localStorage.js" as Settings
 
5
import QtQuick.LocalStorage 2.0
 
6
 
 
7
Component {
 
8
    id: editProfileDialog
 
9
 
 
10
    Dialog {
 
11
        id: editProfileDialogue
 
12
        title: i18n.tr("Edit profile")
 
13
        width: parent.width
 
14
 
 
15
 
 
16
        Column {
 
17
            width: parent.width
 
18
            spacing: units.gu(2)
 
19
 
 
20
            Rectangle{
 
21
                width: 200
 
22
                height: 32
 
23
                radius: 9
 
24
                anchors.horizontalCenter: parent.horizontalCenter
 
25
                TextField {
 
26
                    id:lastnameField
 
27
                    text: Settings.getUserLastName(editUserId)
 
28
                    placeholderText: i18n.tr("Lastname")
 
29
 
 
30
                }
 
31
            }
 
32
            Rectangle{
 
33
                width: 200
 
34
                height: 32
 
35
                radius: 9
 
36
                anchors.horizontalCenter: parent.horizontalCenter
 
37
                TextField {
 
38
                    id:firstnameField
 
39
                    anchors.horizontalCenter: parent.horizontalCenter
 
40
                    placeholderText: i18n.tr("Firstname")
 
41
                    text: Settings.getUserFirstName(editUserId)
 
42
                }
 
43
            }
 
44
 
 
45
 
 
46
            Row{
 
47
                width: parent.width
 
48
                spacing: units.gu(1)
 
49
 
 
50
                SudokuDialogButton{
 
51
                    id:okButton
 
52
                    buttonText: i18n.tr("OK")
 
53
                    width: parent.width/2;
 
54
                    size: units.gu(5)
 
55
                    onTriggered: {
 
56
 
 
57
                        if(lastnameField.text!="" && firstnameField.text!="")
 
58
                        {
 
59
 
 
60
                            if(!Settings.existProfile( lastnameField.text, firstnameField.text))
 
61
                            {
 
62
 
 
63
                                Settings.updateProfile(editUserId, lastnameField.text, firstnameField.text);
 
64
                                var userId = currentUserId
 
65
                                currentUserId = -1
 
66
                                currentUserId = userId
 
67
 
 
68
                                PopupUtils.close(editProfileDialogue)
 
69
                            }else{
 
70
                                PopupUtils.close(editProfileDialogue)
 
71
                            }
 
72
 
 
73
 
 
74
                        } else{
 
75
                            mainView.showAlert(i18n.tr("Warning"), i18n.tr("Lastname and firstname must not be empty."), okButton)
 
76
                        }
 
77
 
 
78
 
 
79
 
 
80
 
 
81
 
 
82
                    }
 
83
                }
 
84
 
 
85
                SudokuDialogButton{
 
86
                    buttonText: i18n.tr("Delete")
 
87
                    width: parent.width/2;
 
88
                    size: units.gu(5)
 
89
                    onTriggered: {
 
90
                        Settings.deleteProfile(editUserId)
 
91
                        if(editUserId == currentUserId)
 
92
                            currentUserId = -1
 
93
 
 
94
 
 
95
                       PopupUtils.close(editProfileDialogue)
 
96
                    }
 
97
                }
 
98
            }
 
99
            SudokuDialogButton{
 
100
                anchors.horizontalCenter: parent.horizontalCenter
 
101
                buttonText: i18n.tr("Cancel")
 
102
                width: parent.width/2;
 
103
                size: units.gu(5)
 
104
                onTriggered: {
 
105
                    PopupUtils.close(editProfileDialogue)
 
106
                }
 
107
            }
 
108
 
 
109
 
 
110
        }
 
111
 
 
112
 
 
113
    }
 
114
}
 
115