{"size": 5330, "ext": "js", "max_stars_repo_path": "app/static/javascript/manager/app/views/location_roles.js", "max_stars_repo_name": "Joey-Wondersign/Staffjoy-suite-Joey", "max_stars_repo_stars_event_min_datetime": "2017-02-25T07:11:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-08T05:49:20.000Z", "max_issues_repo_path": "app/static/javascript/manager/app/views/location_roles.js", "max_issues_repo_name": "Joey-Wondersign/Staffjoy-suite-Joey", "max_issues_repo_issues_event_min_datetime": "2017-02-25T18:07:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-19T13:09:41.000Z", "max_forks_repo_path": "app/static/javascript/manager/app/views/location_roles.js", "max_forks_repo_name": "nfriedly/suite", "max_forks_repo_forks_event_min_datetime": "2017-02-25T09:01:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-19T02:24:02.000Z"}
{"max_stars_count": 890, "max_issues_count": 11, "max_forks_count": 276, "avg_line_length": 35.0657894737, "max_line_length": 124, "alphanum_fraction": 0.4459662289}
(function(root) {

    "use strict";

    var Util = root.App.Util,
        Models = root.App.Models,
        Views = root.App.Views,
        Collections = root.App.Collections
    ;

    var LocationRolesView = Views.Base.extend({
        el: "#manage-main",
        events: {
            "click .edit-role" : "goToRolePreferences",

            "click .role-users .role-user" : "goToUserRole",
            "click .reminder-email": "sendReminderEmail",
        },
        initialize: function(opts) {
            LocationRolesView.__super__.initialize.apply(this);
            this.mainHeaderContentVisible = "roles";

            if (!_.isUndefined(opts)) {
                if (!_.isUndefined(opts.locationId)) {
                    this.locationId = opts.locationId;
                }
            }
        },
        render: function(opts) {
            var self = this,
                RolesCollection = Collections.Base.extend({
                    model: Models.Role,
                }),
                data = {},
                userRoleCollection
            ;

            // check if any roles exist
            if (self.collection.models.length === 0) {
                data["message"] = {
                    type: "info",
                    message: "Create a new role to be scheduled.",
                };
            }

            self.$el.html(ich.location_roles(data));

            _.each(self.collection.models, function(model, index, list) {
                self.addDelegateView(
                    model.get("id"),
                    new Views.LocationRoleCardView({
                        model: model
                    })
                );
            });

            return this;
        },
        getAction: function() {
            var self = this;

            return {
                label: 'Role',
                callback: function() {
                    Backbone.history.navigate("locations/" + self.locationId + "/new-role", {trigger: true});
                },
            };
        },
        goToRolePreferences: function(e) {
            e.preventDefault();
            e.stopPropagation();

            var self = this,
                $target = $(e.target).closest(".role-card"),
                roleId = $target.attr("data-role"),
                locationId = self.locationId
            ;

            Backbone.history.navigate("locations/" + locationId + "/roles/" + roleId + "/preferences", {trigger: true});
        },
        goToUserRole: function(e) {
            e.preventDefault();
            e.stopPropagation();

            var self = this,
                $userTarget = $(e.target).closest(".role-user"),
                userId = $userTarget.attr("data-user-id"),
                $roleTarget = $(e.target).closest(".role-card"),
                roleId = $roleTarget.attr("data-role"),
                locationId = self.locationId
            ;

            Backbone.history.navigate("locations/" + locationId + "/roles/" + roleId + "/users/" + userId, {trigger: true});
        },
        sendReminderEmail: function(e) {
            e.preventDefault();
            e.stopPropagation();

            var self = this,
                $target = $(e.target),
                $userTarget = $target.closest(".role-user"),
                userId = parseInt($userTarget.attr("data-user-id")),
                $roleTarget = $(e.target).closest(".role-card"),
                roleId = parseInt($roleTarget.attr("data-role")),
                roleModel = self.collection.get(roleId),
                userData = _.findWhere(roleModel.get("users"), {id: userId}),
                userModel = new Models.UserRole({id: userId}),
                workerName
            ;

            // construct model
            userModel.set(userData);
            userModel.addUpstreamModel("locationId", self.locationId);
            userModel.addUpstreamModel("roleId", roleId);

            self.addDelegateView(
                "resend-email-modal",
                new Views.Components.MessageModalView({
                    el: ".email-reminder-modal-placeholder",
                    params: {
                        title: "Resend Confirmation Email",
                        actionStatus: "primary",
                        actionLabel: "Resend Email",
                        message: Util.generateConfirmationEmailModalText(userModel.get("email")),
                    },
                    callback: function() {
                        var success = function(model, response, opts) {
                                $.notify({message: "Success"},{type:"success"});
                            },
                            error = function(model, response, opts) {
                                $.notify({message:ERROR_MESSAGE},{type:"danger"});
                            }
                        ;

                        userModel.save(
                            {activateReminder: true},
                            {
                                success: success,
                                error: error,
                                patch: true,
                            }
                        );
                    },
                })
            );
        },
    });

    root.App.Views.LocationRolesView = LocationRolesView;

})(this);
