This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/controllers/avatar_selector_controller.js
2013-08-17 00:35:29 +02:00

47 lines
1.5 KiB
JavaScript

/**
The modal for selecting an avatar
@class AvatarSelectorController
@extends Discourse.Controller
@namespace Discourse
@uses Discourse.ModalFunctionality
@module Discourse
**/
Discourse.AvatarSelectorController = Discourse.Controller.extend(Discourse.ModalFunctionality, {
init: function() {
// copy some data to support the cancel action
this.setProperties(this.get("currentUser").getProperties(
"username",
"has_uploaded_avatar",
"use_uploaded_avatar",
"gravatar_template",
"uploaded_avatar_template"
));
},
toggleUseUploadedAvatar: function(toggle) {
this.set("use_uploaded_avatar", toggle);
},
saveAvatarSelection: function() {
// sends the information to the server if it has changed
if (this.get("use_uploaded_avatar") !== this.get("currentUser.use_uploaded_avatar")) {
var data = { use_uploaded_avatar: this.get("use_uploaded_avatar") };
Discourse.ajax("/users/" + this.get("currentUser.username") + "/preferences/avatar/toggle", { type: 'PUT', data: data });
}
// saves the data back to the currentUser object
var currentUser = this.get("currentUser");
currentUser.setProperties(this.getProperties(
"has_uploaded_avatar",
"use_uploaded_avatar",
"gravatar_template",
"uploaded_avatar_template"
));
if (this.get("use_uploaded_avatar")) {
currentUser.set("avatar_template", this.get("uploaded_avatar_template"));
} else {
currentUser.set("avatar_template", this.get("gravatar_template"));
}
}
});