~ubuntu-branches/ubuntu/maverick/kdeutils/maverick-proposed

« back to all changes in this revision

Viewing changes to okteta/kasten/controllers/view/structures/schema/example/dynamic-array-js/main.js

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-05-28 09:49:30 UTC
  • mfrom: (1.2.44 upstream)
  • Revision ID: james.westby@ubuntu.com-20100528094930-jzynf0obv1n2v13a
Tags: 4:4.4.80-0ubuntu1~ppa1
New upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
var typeEnumValues = {
 
2
    char : 0,
 
3
    int16 :1,
 
4
    int32 : 2,
 
5
}
 
6
 
 
7
function init() {
 
8
    var object = struct({
 
9
        //should be no longer than 100
 
10
        len: uint8(),
 
11
        arrayType : enumeration("TypeEnum", uint8(), typeEnumValues),
 
12
        // length of this array is always equal to min(len.value, 100)
 
13
        dynArray : array(uint8(), 10, null, updateLength),
 
14
        
 
15
        //this array changes type depending on the value of arrayType
 
16
        typeChangingArray : array(char(), 10, null, updateType),
 
17
    },validateLength);
 
18
    return object;
 
19
}
 
20
 
 
21
function updateLength(mainStruct) {
 
22
    //set the array length to the correct length (no more than 100)
 
23
    var newLen = mainStruct.len.value;
 
24
    if (newLen > 100)
 
25
        newLen = 100;
 
26
    this.length = newLen;
 
27
}
 
28
 
 
29
function updateType(mainStruct) {
 
30
    var type = mainStruct.arrayType.value;
 
31
    if (type == typeEnumValues.char && this.childType != char())
 
32
        this.setArrayType(char());
 
33
    else if (type == typeEnumValues.int16 && this.childType != int16())
 
34
        this.setArrayType(int16());
 
35
    else if (type == typeEnumValues.int32 && this.childType != int32())
 
36
        this.setArrayType(int32());
 
37
}
 
38
 
 
39
function validateLength() {
 
40
    if (this.len.value > 100)
 
41
        this.len.validationError = "len must be no bigger than 100";
 
42
    else
 
43
        this.len.valid = true;
 
44
    
 
45
    var type = this.arrayType.value;
 
46
    if (type == 0 || type == 1 || type == 2)
 
47
        this.arrayType.valid = true;
 
48
    else
 
49
        this.arrayType.validationError = "value is not in enum";
 
50
}