PageSourceSearch

https://ta-tum.com/js/modules/teacher/profile/section/Profile.js

js ta-tum.com collected 2026-09-24 11:29:37 UTC 7,833 bytes, 204 lines download raw bytes

1/**
2 * Module Profile Profile
3 * @description 
4 * @author Alejandro Micheloud
5 */
6
7var TeacherProfileProfile = function (sco) {
8    var scope = sco;
9    var builded = false;
10
11    /**
12     * Se invoca cuando el módulo recibe foco
13     * @returns {undefined}
14     */
15    function show() {
16        if (!builded) {
17            build(doStart);
18        } else {
19            doStart();
20        }
21    }
22
23    function doStart() {
24        console.log("TeacherProfileProfile.doStart()")
25        $(".d-profile .d-avatar").html(getHtmlTeacherAvatar(mDiscover.getUser(), ""));
26        //$(".d-profile .d-username.input").html(mDiscover.getUser().username);
27        $(".d-profile .d-name.input").html(mDiscover.getUser().name);
28        $(".d-profile .d-lastname.input").html(mDiscover.getUser().lastname);
29        $(".d-profile select.d-treatment").val(mDiscover.getUser().treatment);
30        setTreatmentTitle();
31
32        scope.show();
33
34        getClassrooms();
35    }
36    function setTreatmentTitle() {
37        $(".d-profile .d-title").html(mDiscover.getUser().treatment === "mr" ? lang.profile_teacher_treatment_0 : lang.profile_teacher_treatment_1);
38    }
39
40    function saveChanges() {
41        mDiscover.showLoading();
42        mCom.ajax("profile", "PUT", {
43            role: 'teacher',
44            treatment: $(".d-profile select.d-treatment").val(),
45            name: $(".d-profile .d-name.input").text(),
46            lastname: $(".d-profile .d-lastname.input").text()
47        },
48        function (data, status) {
49            mDiscover.hideLoading();
50            mToast.toast(lang.profile_save_ok, 3000);
51            mDiscover.updUserProfile(data);
52            setTreatmentTitle();
53        }, function (err, status, msg) {
54            mDiscover.hideLoading();
55            mToast.toast(lang.profile_save_notok, 3000);
56        });
57    }
58
59    function onUpdateUser() {
60        if (mDiscover.getUser().avatar !== "") {
61            scope.find(".d-avatar .d-avatar-image").attr("style", "background-image:url(" + mDiscover.getUser().avatar + "?t=" + new Date().getTime() + ")");
62        }
63    }
64
65    function getClassrooms() {
66        scope.find(".d-classroom-container").html(getHtmlLoader());
67
68        mCom.ajax("classroom/teacher", "GET", "", function (data, status) {
69            if (status === "success") {
70                renderClassrooms(data.classrooms);
71            }
72        }, function (err, status, msg) {
73            mToast.toast(lang.school_get_error, 3000);
74        });
75
76    }
77    function renderClassrooms(data) {
78
79        $cardcontainer = scope.find(".d-classroom-container");
80        $cardcontainer.html("");
81
82        if (typeof data !== "undefined") {
83            for (var i = 0; i < data.length; i++) {
84                var classroom = data[i];
85                $cardcontainer.append(getHtmlCardProject(classroom));
86                var card = $cardcontainer.find(".d-classroom").last();
87                card.data(classroom);
88                // image
89                if (classroom.avatar !== "") {
90                    card.find(".d-icon").css("background-image", "url(" + classroom.avatar + "?t=" + new Date().getTime() + ")");
91                }
92            }
93        }
94        $cardcontainer.find(".d-classroom").click(function () {
95            var classroom = $(this).data();
96            console.log(classroom);
97            routie("teacher/classroom/" + classroom.guid + "/projects");
98        });
99
100        // add new class
101        $cardcontainer.append(getHtmlCardNew());
102
103        $cardcontainer.find(".d-classroom.add").click(function () {
104            routie("teacher/home/classroom/add");
105        });
106
107    }
108
109    function printCarnet() {
110        window.open(config.api + "teacher/pdf/" + mDiscover.getSession() + "/carnet-profesor.pdf", "_blank");
111    }
112
113    /**
114     * Constructor de módulo
115     * @returns {undefined}
116     */
117    function build(callback) {
118
119        builded = true;
120
121        scope.html(getHtmlModule());
122
123        scope.find(".d-profile .d-print").off("click").on("click", printCarnet);
124        scope.find(".d-profile .d-submit").off("click").on("click", saveChanges);
125
126        $("body").off("on_update_user", onUpdateUser).on("on_update_user", onUpdateUser);
127
128        if (isFunction(callback)) {
129            callback();
130        }
131    }
132
133    /**
134     * Constructor
135     * @returns {undefined}
136     */
137    function init() {
138        // nada, latente hasta show
139    }
140    init();
141
142    // helpers
143    /* html of module */
144    function getHtmlModule() {
145        return '<div class="d-teacher-m-profile">' +
146                '   <div class="d-profile standard-shadow-1"> ' +
147                '       <div class="d-card-profile-title">' + lang.profile_my_personal_dates + '</div>' +
148                '       <div class="d-card-profile"> ' +
149                '           <div class="d-title-depto">' + lang.profile_escuela_de_detectives + '</div>' +
150                '           <div class="d-title"></div>' +
151                '           <div class="d-treatment"></div>' +
152                '            <select class="d-treatment">' +
153                '                <option value="mr">' + lang.register_teacher_treatment_mr + '</option>' +
154                '                <option value="mrs">' + lang.register_teacher_treatment_mrs + '</option>' +
155                '            </select>' +
156                '           <div class="d-name label">' + lang.profile_teacher_name + '</div>' +
157                '           <div class="d-name input" contenteditable="true">Agustín J.</div>' +
158                '           <div class="d-lastname label">' + lang.profile_teacher_lastname + '</div>' +
159                '           <div class="d-lastname input" contenteditable="true">Blanco García</div>' +
160                '           <div class="d-avatar"></div>' +
161                '       </div>' +
162                '       <div class="d-footer">' +
163                '           <div class="d-print btn brown">' + lang.profile_teacher_print + '</div>' +
164                '           <div class="d-submit btn btn orange">' + lang.profile_teacher_save_changes + '</div>' +
165                '       </div>' +
166                '   </div> ' +
167                '   <div class="d-separator"></div>' +
168                '   <div class="d-classrooms standard-shadow-1"> ' +
169                '       <div class="d-title">' + lang.profile_teacher_my_classrooms + '</div>' +
170                '       <div class="d-classroom-container"></div>' +
171                '   </div> ' +
172                '   <div class="d-separator"></div>' +
173                '</div>';
174    }
175    function getHtmlCardProject(classroom) {
176        var students = '';
177        if (classroom.amount_students === 0) {
178            students = " " + lang.classroom_info_wo_researcher;
179        } else if (classroom.amount_students === 1) {
180            students = classroom.amount_students + " " + lang.classroom_info_researcher;
181        } else {
182            students = classroom.amount_students + " " + lang.classroom_info_researchers;
183        }
184        return '<div class="d-classroom btn">' +
185                '   <div class="d-icon"></div>' +
186                '   <div class="d-icon-bg"></div>' +
187                '   <div class="d-name">' + classroom.name + '</div>' +
188                '   <div class="d-level">' + classroom.education_level + '</div>' +
189                '   <div class="d-students">' + students + '</div>' +
190                '</div>';
191    }
192    function getHtmlCardNew() {
193        return '<div class="d-classroom add btn">' +
194                '   <div class="d-icon-add"></div>' +
195                '   <div class="d-title">' + lang.profile_teacher_create_classroom + '</div>' +
196                '</div>';
197    }
198    function getHtmlLoader() {
199        return '<div class="d-loader"><img src="css/img/loading_gears.gif" /></div>';
200    }
201
202    // public methods
203    this.show = show;
204};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.