Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.

My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.


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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<div id='stealtheticket'>
    <input type='button' value='Take the Ticket' onclick='do_action();'>
    <div style='padding: 4px; font-weight: bold; font-size: 18px;'>
        <div id='stealtheticket_status'></div>
        <div id='stealtheticket_error'></div>
    </div>
</div>

<script type="javascript">
    // This is the main bit of code, the action that occurs when the "Do" button is hit.
    // All other methods should be put into their own little sections
    var current_callbacks = {};

    log_error = function(arg) {
        $('stealtheticket_error').innerHTML = arg;
    }

    log_status = function(arg) {
        $('stealtheticket_status').innerHTML = arg;
    }

    fade_status = function(arg) {
        setTimeout( function() {
            log_status('');
        }, 3000);
    }
do_action = function() {

        var current_action = 'steal_ticket';

        if (current_action) {
            var callback = current_callbacks[current_action];
            callback();
        }
    }


    Event.observe(window, 'widgets:load', function() {
        current_callbacks['not_yet'] = function() {
            log_status("Sorry, that function isn't done yet. :(");
            fade_status();
        }

        current_callbacks['steal_ticket'] = attempt_steal;

    });

    get_current_user_id = function() {
        var _current_user_id = 0;
        agents.each( function(row) {
            if (row['name'] == "{{current_user.name}}") {
                _current_user_id = row['id'];
            }
        });
        return _current_user_id;
    }

</script>


<script type="javascript">
    // this is all the code for the ticket stealing function.
    var ticket_id = {{ticket.id}};
    var can_update_ticket = false;
    var assignee_name = 'Unknown';

    attempt_steal = function() {
        log_status("Checking one last time...");
        check_on_ticket(function() {
            do_steal();
        });
    }

    do_steal = function() {
        log_status('Starting...');

        var do_it = false;
        if (can_update_ticket == false) {
            do_it = confirm("This ticket is already owned by " + assignee_name + "\n\nClicking OK will assign this ticket to you.");
        } else {
            do_it = true;
        }

        if (do_it) {
            new Ajax.Request('/tickets/' + ticket_id + '.xml?_method=put', {
                method:'PUT',
                asynchronous: true,
                contentType: "application/xml",
                postBody: "<ticket><assignee-id type=\"integer\">" + get_current_user_id() + "</assignee-id></ticket>",
                //postBody: '{"ticket": {"assignee-id": ' + current_user_id + '}}',
                onSuccess: function(transport) {
                    var obj = transport.responseText;
                    log_status("Owner = You");
                    fade_status();
                    $$('select#ticket_assignee_id option').each( function(item) {
                        if (item.value == get_current_user_id()) {
                            item.selected = true;
                        }
                    });
                },
                onException: function(transport) {
                    log_error('exception: ' + transport.responseText);
                },
                onFailure: function(transport) {
                    log_error('failure: ' + transport.responseText);
                }
            });            
        }
    }

    check_on_ticket = function(cb_on_success) {
        log_status("Attempting to find owner.");

        new Ajax.Request('/tickets/' + ticket_id + '.json', {
            method:'GET',
            asynchronous: true,
            onSuccess: function(transport) {
                var obj = transport.responseText.evalJSON();
                ticket_id = obj['nice_id'];
                assignee_name = 'None';

                agents.each( function(row) {
                    if (row['id'] == obj['assignee_id']) {
                        assignee_name = row['name'];
                    }
                });

                log_status("Current Owner: " + assignee_name);

                if (assignee_name == 'None') {
                    can_update_ticket = true;
                } else {
                    can_update_ticket = false;
                }

                if (cb_on_success !== undefined) {
                    cb_on_success();
                }
            },
            onException: function(transport) {
                log_error('exception: ' + transport.responseText);
            },
            onFailure: function(transport) {
                log_error('failure: ' + transport.responseText);
            }
        });
    }

</script>