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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*function action_test_right() {
    alert("test");
}*/

Behaviour.register({
  '#Form_EditForm': {
    initialise : function() {
        // falls ich noch irgendwas initialisieren muss (bei meinem Frickeln seeeeehr
        // unwahrscheinlich :D
        this.prepareForm();
    },

    prepareForm : function() {
        ajaxActionsAtTop('Form_EditForm', 'form_actions_right', 'right');
    },

    /*
     * Die rechte Seite vom Server anfordern.
     * id - ID der Mannschaft
     * what - (team => Teameinstellungen),(players => Spielerübersicht),(news => Newsübersicht)
     */
    getPageFromServer : function(id, what ) {
        if(id && parseInt(id) == id) {
            this.receivingID = id;
            this.treenodename = what+"-"+id;
            // Der Treenode könnte nicht existieren, wenn der Baum geschlossen ist.
            var treenode = $('sitetree').getTreeNodeByIdx(what+"-"+id);
            if(treenode) treenode.addNodeClass('loading');
            statusMessage('loading...');

            var requestURL = '/admin/teammanagement/show'+what+'/'+id;

            new Ajax.Request(baseHref()+requestURL, {
                asynchronous: true,
                method: 'post',
                postBody: 'ajax=1',
                onSuccess: this.successfullyReceivedPage.bind(this),
                onFailure: function(response) {
                    if(treenode) treenode.removeNodeClass('loading');
                    errorMessage('error loading page',response);
                }
            });
        }
    },

    successfullyReceivedPage : function(response) {
        this.loadNewPage(response.responseText);

        // Der Treenode könnte nicht existieren.
        var treeNode = $('sitetree').getTreeNodeByIdx(this.treenodename);
        if(treeNode) {
            $('sitetree').changeCurrentTo(treeNode);
            treeNode.removeNodeClass('loading');
        }
        statusMessage('');

        if(typeof onload_init_tabstrip != 'undefined') onload_init_tabstrip();

        if( this.openTab ) {
        openTab( this.openTab );
        this.openTab = null;
        }
	},

    /**
     * Die Seite in den rechten Teil des Adminmenü laden.
     */
    loadNewPage : function(formContent) {
        rightHTML = formContent;
        rightHTML = rightHTML.replace(/href *= *"#/g, 'href="' + window.location.href.replace(/#.*$/,'') + '#');

        // Prepare iframes for removal, otherwise we get loading bugs
        var i, allIframes = this.getElementsByTagName('iframe');
        if(allIframes) for(i=0;i<allIframes.length;i++) {
            allIframes[i].contentWindow.location.href = 'about:blank';
            allIframes[i].parentNode.removeChild(allIframes[i]);
        }

        this.innerHTML = rightHTML;

        allIframes = this.getElementsByTagName('iframe');
        if(allIframes) for(i=0;i<allIframes.length;i++) {
            try {
                allIframes[i].contentWindow.location.href = allIframes[i].src;
            } catch(er) {alert('Error in NewsletterAdmin_right.js #Form_EditForm::loadNewPage(): ' + er.message);}
        }

        _TAB_DIVS_ON_PAGE = [];

        try {
            var tabs = document.getElementsBySelector('#Form_EditForm ul.tabstrip');
        } catch(er) {/* alert('a: '+ er.message + '\n' + er.line);*/ }
        try {
            for(var i=0;i<tabs.length;i++) if(tabs[i].tagName) initTabstrip(tabs[i]);
        } catch(er) { /*alert('b: '+ er.message + '\n' + er.line); */}

        if((typeof tinymce != 'undefined') && tinymce.EditorManager) {
            tinymce.EditorManager.editors = [];
        }

        if(typeof onload_init_tabstrip != 'undefined') onload_init_tabstrip();

        // if(this.prepareForm) this.prepareForm();
        Behaviour.apply($('Form_EditForm'));
        if(this.prepareForm)
            this.prepareForm();

        this.resetElements();

        window.ontabschanged();

    },

    saveTeam: function() {
        alert("test");
    },

    test: function() {
        alert("testfunktion");
    },

    save: function(ifChanged, callAfter) {

        _AJAX_LOADING = true;
        if(typeof tinyMCE != 'undefined') tinyMCE.triggerSave();

        var __callAfter = callAfter;
        var __form = this;

        //if(__form.notify) __form.notify('BeforeSave', __form.elements.ID.value);

        var success = function(response) {

            alert("antwort: "+response.responseText);

            Ajax.Evaluator(response);
            __form.resetElements();

            if(__callAfter) __callAfter();
            //if(__form.notify) __form.notify('PageSaved', __form.elements.ID.value);
            _AJAX_LOADING = false;
        }

        var action = 'action_save';

        if(ifChanged) {
            var data = this.serializeChangedFields('ID') + '&ajax=1&' + action + '=1';
        } else {
            var data = this.serializeAllFields() + '&ajax=1&' + action + '=1';
        }

        alert(this.action + '\n\n' + data);

        new Ajax.Request(this.action, {
            method : this.method,
            postBody: data,
            onSuccess : success,
            onFailure : function(response) {
                alert(response.responseText);
                errorMessage('Error saving content', response);
                _AJAX_LOADING = false;
            }
        });
    }
  }
}
);