File size: 1,907 Bytes
cbc76af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/// <reference path="_references.js" />
var $createForm = $('#create-section').find('#create-achievement-form');
$createForm.find('#submit').on('click', function () {
    var title = $createForm.find('#achievement-title').val();
    var description = $createForm.find('#achievement-description').val();
    var proof = $createForm.find('#achievement-proof').val();
    var reward = $createForm.find('#achievement-reward').val();
    var category = $createForm.find('#achievement-category').val();
    var startDate = $createForm.find('#achievement-start-time').val();
    var endDate = $createForm.find('#achievement-finish-time').val();
    var id = sampleAchievements.length + 1;

    var newAchievement = {
        id: id,
        title: title,
        description: description,
        reward: reward,
        proof: proof,
        author: 'currentUser',
        category: category,
        linkedAchievements: [],
        startDate: startDate,
        endDate: endDate
    };

    addNewAchievement(newAchievement);
    refreshBrowseAchContent();

    refreshLatestAchContent();
    refreshContainerWidth();

    alert('Achievement was added successfully!');
    clearFields();
})

function refreshContainerWidth() {
    $('section#browse-section div.browsed-achievements-container').css('width', sampleAchievements.length * 180 + 'px');
}

function addNewAchievement(newAch) {
    var n = new Achievement(newAch);
    sampleAchievements.push(n);

    console.dir(sampleAchievements);
}

function clearFields() {
    $createForm.find('#achievement-title').val('');
    $createForm.find('#achievement-description').val('');
    $createForm.find('#achievement-proof').val('');
    $createForm.find('#achievement-reward').val('');
    $createForm.find('#achievement-category').val('');
    $createForm.find('#achievement-start-time').val('');
    $createForm.find('#achievement-finish-time').val('');
}