~boghison/lang/trunk

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
import QtQuick 2.0

import Ubuntu.Components 1.1
import Ubuntu.Components.Popups 1.0

import "../components"

Dialog {
    id: dialog

    title: i18n.tr("Add Vocabulary Collection")

    text: i18n.tr("Enter the name of the language and pick a color for it:")

    TextField {
        id: langField
        width: parent.width

        placeholderText: i18n.tr("Language name")

        validator: RegExpValidator {
            regExp: /.+/
        }
    }

    Label {
        text: i18n.tr("Preview (tap to change color)")
    }


    Item {
        height: units.gu(20)

        // The UbuntuShape is within a wrapper Item because the Dialog forces all children items
        // to be full-width.
        UbuntuShape {
            id: colorShape
            width: units.gu(15)
            height: units.gu(20)
            color: "#0000ff"

            anchors.horizontalCenter: parent.horizontalCenter

            MouseArea {
                anchors.fill: parent
                onClicked: {
                    var colorArray = ["#0000ff", "#800080", "#ffa500", "#00ff00", "#30d5c8", "#000000", "#ff0000", "#ffc0cb", "#a5682a"];
                    colorShape.color = (String(colorShape.color) !== colorArray[colorArray.length - 1]) ? colorArray[colorArray.indexOf(String(colorShape.color)) + 1] : colorArray[0]
                }
            }

            Label {
                text: langField.text
                color: "white"
                anchors.centerIn: parent
            }
        }
    }

    DialogButtonRow {
        enabled: langField.acceptableInput

        onAccepted: {
            PopupUtils.close(dialog)

            var tempContents = {};
            tempContents = vocabDB.contents;
            var existing;
            for (var i = 0; i < tempContents["vocabularies"].length; i++) {
                if (tempContents["vocabularies"][i].color == colorShape.color && tempContents["vocabularies"][i].name == langField.text) existing = true
            }
            if (existing == null) {
                tempContents["vocabularies"].push({"name": langField.text, "color": colorShape.color, "translations": [], "definitions": []});
                vocabDB.contents = tempContents;
                PopupUtils.close(addVocabDialog);
                mainStack.clear();
                mainStack.push(vocabPage);
            }
        }

        onRejected: PopupUtils.close(dialog)
    }
}