~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/javascript/subscription.js

  • Committer: Steve Kowalik
  • Date: 2011-08-07 04:05:52 UTC
  • mto: This revision was merged to the branch mainline in revision 13626.
  • Revision ID: stevenk@ubuntu.com-20110807040552-mwnxo0flmhvl35e8
Correct the notification based on review comments, and remove request{,ed}
from the function names, switching to create{,d}.

Show diffs side-by-side

added added

removed removed

Lines of Context:
997
997
    );
998
998
}
999
999
 
1000
 
function make_action_link_function (
1001
 
    node, sprite_class, method_name, handler, parameters, client) {
1002
 
    // Performs the heavy lifting for make_action_link.
1003
 
    var config = {
1004
 
        on: {success:
1005
 
            function (maybe_sub) {
1006
 
                node.replaceClass('spinner', sprite_class);
1007
 
                var info = LP.cache.bug_subscription_info;
1008
 
                var old = info.direct.personal[0];
1009
 
                if (Y.Lang.isValue(maybe_sub)) {
1010
 
                    // Set the subscription in info and in cache.
1011
 
                    var sub = maybe_sub.getAttrs();
1012
 
                    if (Y.Lang.isValue(old)) {
1013
 
                        info.direct.personal[0].subscription = sub;
1014
 
                    } else {
1015
 
                        // We don't have enough information to calculate
1016
 
                        // everything on the fly. Luckily, we don't need
1017
 
                        // most of it, and we think it is alright to not
1018
 
                        // include the extra information about
1019
 
                        // principal_is_reporter, security_contact_pillars,
1020
 
                        // and bug_supervisor_pillars.
1021
 
                        info.direct.personal.push(
1022
 
                            {principal: {},
1023
 
                            bug: {},
1024
 
                            subscription: sub,
1025
 
                            principal_is_reporter: false,
1026
 
                            security_contact_pillars: [],
1027
 
                            bug_supervisor_pillars: []
1028
 
                           });
1029
 
                       info.direct.count += 1;
1030
 
                       info.count += 1;
1031
 
                   }
1032
 
               } else {
1033
 
                   if (Y.Lang.isValue(old)) {
1034
 
                       info.direct.personal.pop();
1035
 
                       info.direct.count -= 1;
1036
 
                       info.count -= 1;
1037
 
                   }
1038
 
               }
1039
 
               if (method_name === 'mute') {
1040
 
                   info.muted = true;
1041
 
               } else if (method_name === 'unmute') {
1042
 
                   info.muted = false;
1043
 
               }
1044
 
               reveal_direct_description_actions(
1045
 
                   Y.one('#direct-subscription'),
1046
 
                   get_direct_subscription_information(info));
1047
 
            },
1048
 
        failure: handler.getFailureHandler()},
1049
 
        parameters: parameters
1050
 
    };
1051
 
    node.replaceClass(sprite_class, 'spinner');
1052
 
    client.named_post(LP.cache.context.bug_link, method_name, config);
1053
 
}
1054
 
 
1055
1000
/**
1056
1001
 * Makes links for all kinds of actions.
1057
1002
 *
1085
1030
        'click',
1086
1031
        function (e) {
1087
1032
            e.halt();
1088
 
            var method_call = function() {
1089
 
                make_action_link_function(
1090
 
                    node, sprite_class, method_name, handler, parameters,
1091
 
                    client);
 
1033
            var config = {
 
1034
                on: {success:
 
1035
                        function (maybe_sub) {
 
1036
                            node.replaceClass('spinner', sprite_class);
 
1037
                            var info = LP.cache.bug_subscription_info;
 
1038
                            var old = info.direct.personal[0];
 
1039
                            if (Y.Lang.isValue(maybe_sub)) {
 
1040
                                // Set the subscription in info and in cache.
 
1041
                                var sub = maybe_sub.getAttrs();
 
1042
                                if (Y.Lang.isValue(old)) {
 
1043
                                    info.direct.personal[0].subscription =
 
1044
                                        sub;
 
1045
                                } else {
 
1046
                                    // We don't have enough information to
 
1047
                                    // calculate everything on the fly.
 
1048
                                    // Luckily, we don't need most of it,
 
1049
                                    // and we think it is alright to not
 
1050
                                    // include the extra information about
 
1051
                                    // principal_is_reporter,
 
1052
                                    // security_contact_pillars, and
 
1053
                                    // bug_supervisor_pillars.
 
1054
                                    info.direct.personal.push(
 
1055
                                        {principal: {},
 
1056
                                         bug: {},
 
1057
                                         subscription: sub,
 
1058
                                         principal_is_reporter: false,
 
1059
                                         security_contact_pillars: [],
 
1060
                                         bug_supervisor_pillars: []
 
1061
                                        });
 
1062
                                    info.direct.count += 1;
 
1063
                                    info.count += 1;
 
1064
                                }
 
1065
                            } else {
 
1066
                                if (Y.Lang.isValue(old)) {
 
1067
                                    info.direct.personal.pop();
 
1068
                                    info.direct.count -= 1;
 
1069
                                    info.count -= 1;
 
1070
                                }
 
1071
                            }
 
1072
                            if (method_name === 'mute') {
 
1073
                                info.muted = true;
 
1074
                            } else if (method_name === 'unmute') {
 
1075
                                info.muted = false;
 
1076
                            }
 
1077
                            reveal_direct_description_actions(
 
1078
                                Y.one('#direct-subscription'),
 
1079
                                get_direct_subscription_information(info));
 
1080
                         },
 
1081
                     failure: handler.getFailureHandler()
 
1082
                    },
 
1083
                parameters: parameters
1092
1084
            };
1093
 
            // If this a private bug, and the user is unsubscribing
1094
 
            // themselves, give them a warning.
1095
 
            if (
1096
 
                method_name === 'unsubscribe' &&
1097
 
                Y.Lang.isBoolean(LP.cache.bug_is_private) &&
1098
 
                LP.cache.bug_is_private) {
1099
 
                var content = [
1100
 
                    '<p>You will not have access to this bug or any of ',
1101
 
                    'its pages if you unsubscribe. If you want to stop ',
1102
 
                    'emails, choose the "Mute bug mail" option.</p><p>Do ',
1103
 
                    'you really want to unsubscribe from this bug?</p>'
1104
 
                    ].join('');
1105
 
                var ns = Y.lp.app.confirmationoverlay;
1106
 
                var co = new ns.ConfirmationOverlay({
1107
 
                    submit_fn: method_call,
1108
 
                    form_content: content,
1109
 
                    headerContent: 'Unsubscribe from this bug'
1110
 
                });
1111
 
                co.show();
1112
 
            } else {
1113
 
                method_call();
1114
 
            }
1115
 
        });
 
1085
            node.replaceClass(sprite_class, 'spinner');
 
1086
            client.named_post(
 
1087
                LP.cache.context.bug_link,
 
1088
                method_name,
 
1089
                config);
 
1090
        }
 
1091
    );
1116
1092
    return node;
1117
1093
}
1118
1094
namespace._make_action_link = make_action_link;
1371
1347
 
1372
1348
}, '0.1', {requires: [
1373
1349
    'dom', 'event', 'node', 'substitute', 'lazr.effects', 'lp.app.errors',
1374
 
    'lp.app.confirmationoverlay', 'lp.client'
 
1350
    'lp.client'
1375
1351
]});