~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/javascript/structural-subscription.js

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-05-18 18:50:39 UTC
  • mfrom: (13033.2.4 bug-777786)
  • Revision ID: launchpad@pqm.canonical.com-20110518185039-h7f6fmiryyo7a2np
[r=gmb][bug=777786] instead of an ineffectual "stop email" link,
        give users the option to contact the subscribing team

Show diffs side-by-side

added added

removed removed

Lines of Context:
1239
1239
                    } else {
1240
1240
                        filter_info.is_muted = false;
1241
1241
                    }
1242
 
                    handle_mute(node, filter_info.is_muted);
 
1242
                    handle_mute(node, filter_info);
1243
1243
                    },
1244
1244
                 failure: error_handler.getFailureHandler()
1245
1245
                }
1304
1304
/**
1305
1305
 * For a given filter node, set it up properly based on mute state.
1306
1306
 */
1307
 
function handle_mute(node, muted) {
 
1307
function handle_mute(node, filter_info) {
1308
1308
    var control = node.one('a.mute-subscription');
1309
1309
    var label = node.one('em.mute-label');
1310
1310
    var description = node.one('.filter-description');
1311
 
    if (muted) {
 
1311
    if (filter_info.is_muted) {
1312
1312
        control.set('text', 'Send my emails for this subscription');
1313
1313
        control.replaceClass(MUTE_ICON_CLASS, UNMUTE_ICON_CLASS);
1314
1314
        label.setStyle('display', null);
1335
1335
        '<strong class="filter-name"></strong>'));
1336
1336
 
1337
1337
    if (filter_info.can_mute) {
1338
 
        filter_node.appendChild(Y.Node.create(
1339
 
            '<em class="mute-label" style="padding-left: 1em;">You '+
1340
 
                'do not receive emails from this subscription.</em>'));
 
1338
        filter_node.append(Y.Node.create('<em/>')
 
1339
            .set('text', 'You do not receive emails from this subscription.')
 
1340
            .addClass('mute-label')
 
1341
            .setStyle('paddingLeft', '1em'));
1341
1342
    }
1342
1343
 
1343
1344
    var control = filter_node.appendChild(
1344
1345
        Y.Node.create('<span style="float: right"></span>'));
1345
1346
 
1346
1347
    if (filter_info.can_mute) {
1347
 
        var link = control.appendChild(Y.Node.create(
1348
 
            '<a href="#" class="sprite js-action mute-subscription"></a>'));
1349
 
        var help = control.appendChild(Y.Node.create(
1350
 
            '<a target="help" class="sprite maybe mute-help"'+
1351
 
            '    style="visibility: hidden;"'+
1352
 
            '    href="/+help/structural-subscription-mute.html">'+
1353
 
            '  <span class="invisible-link">Delivery help</span>'+
1354
 
            '</a>'));
 
1348
        var link = control.appendChild(Y.Node.create('<a/>')
 
1349
            .set('href', '#')
 
1350
            .addClass('sprite')
 
1351
            .addClass('js-action')
 
1352
            .addClass('mute-subscription'));
 
1353
        var help = control.appendChild(Y.Node.create('<a/>')
 
1354
            .set('href', '/+help/structural-subscription-mute.html')
 
1355
            .set('target', 'help')
 
1356
            .addClass('sprite')
 
1357
            .addClass('maybe')
 
1358
            .addClass('mute-help')
 
1359
            .setStyle('visibility', 'hidden')
 
1360
            .append(Y.Node.create('<span/>')
 
1361
                .addClass('invisible-link')
 
1362
                .set('text', 'Delivery help')));
1355
1363
        // For some reason the help link will not appear in Chrome unless
1356
1364
        // there is a non-empty element immediately after the help node.
1357
1365
        control.append(Y.Node.create('<span>&nbsp;</span>'));
1362
1370
            help.setStyle('visibility', 'visible');
1363
1371
            // Every time we trigger the display of the help link we need to
1364
1372
            // cancel any pending hiding of the help link so it doesn't
1365
 
            // dissapear on us.  If there isn't one pending, this is a NOP.
 
1373
            // disappear on us.  If there isn't one pending, this is a NOP.
1366
1374
            clearTimeout(hide_help_timeout);
1367
1375
        };
1368
1376
        var hide_help = function () {
1376
1384
 
1377
1385
    if (can_edit(filter_info)) {
1378
1386
        // User can edit the subscription.
1379
 
        control.append(Y.Node.create(
1380
 
            '<a href="#" style="margin-right: 2em;"'+
1381
 
            '    class="sprite modify edit js-action edit-subscription">'+
1382
 
            '  Edit this subscription</a>'+
1383
 
            '<a href="#" class="sprite modify remove js-action '+
1384
 
            '    delete-subscription">Unsubscribe</a>'));
1385
 
    }
1386
 
 
1387
 
    filter_node.appendChild(
1388
 
        Y.Node.create('<div style="padding-left: 1em" '+
1389
 
                      'class="filter-description"></div>'));
 
1387
        control.append(Y.Node.create('<a/>')
 
1388
            .set('href', '#')
 
1389
            .set('text', 'Edit this subscription')
 
1390
            .setStyle('marginRight', '2em')
 
1391
            .addClass('sprite')
 
1392
            .addClass('modify')
 
1393
            .addClass('edit')
 
1394
            .addClass('js-action')
 
1395
            .addClass('edit-subscription'));
 
1396
        control.append(Y.Node.create('<a/>')
 
1397
            .set('href', '#')
 
1398
            .set('text', 'Unsubscribe')
 
1399
            .addClass('sprite')
 
1400
            .addClass('modify')
 
1401
            .addClass('remove')
 
1402
            .addClass('js-action')
 
1403
            .addClass('delete-subscription'));
 
1404
    }
 
1405
 
 
1406
    if (filter_info.team_has_contact_address
 
1407
            && !filter_info.user_is_team_admin) {
 
1408
        var subject = urlEncode('Team contact address and subscriptions');
 
1409
        var user_participation;
 
1410
        if (filter_info.user_is_on_team_mailing_list) {
 
1411
            user_participation = 'subscribe to the team\'s mailing list';
 
1412
        } else {
 
1413
            user_participation = 'be a part of the team';
 
1414
        }
 
1415
        var message = urlEncode(
 
1416
            'Hello.  I receive email notifications about bugs in '+
 
1417
            filter_info.target_title+' because of a team subscription for '+
 
1418
            filter_info.subscriber_title+'. I would like to continue to '+
 
1419
            user_participation+', but I would like to receive less email '+
 
1420
            'from this subscription.  Could you remove the team contact '+
 
1421
            'email address so that the team members can manage their own '+
 
1422
            'subscriptions (see '+filter_info.subscriber_url+'), or delete '+
 
1423
            'or reduce level of the subscription itself (see '+
 
1424
            filter_info.target_bugs_url+'/+subscriptions)?\n\nThank you.');
 
1425
        control.append(Y.Node.create('<a/>')
 
1426
            .set('href', filter_info.subscriber_url+'/+contactuser'+
 
1427
                '?field.message='+message+'&field.subject='+subject)
 
1428
            .set('text', 'Request team administrators change'));
 
1429
    }
 
1430
 
 
1431
    filter_node.append(Y.Node.create('<div/>')
 
1432
        .setStyle('paddingLeft', '1em')
 
1433
        .addClass('filter-description'));
1390
1434
 
1391
1435
    if (filter_info.can_mute) {
1392
 
        handle_mute(filter_node, filter_info.is_muted);
 
1436
        handle_mute(filter_node, filter_info);
1393
1437
    }
1394
1438
 
1395
1439
    fill_filter_description(filter_node, filter_info, filter);
1397
1441
    return filter_node;
1398
1442
}
1399
1443
 
 
1444
// Expose in the namespace for testing purposes.
 
1445
namespace._create_filter_node = create_filter_node;
 
1446
 
 
1447
 
1400
1448
/**
1401
1449
 * Create a node with subscription description.
1402
1450
 */
1424
1472
        // and see the information you expect to see.
1425
1473
        LP.cache['structural-subscription-filter-'+filter_id.toString()] =
1426
1474
            filter;
1427
 
        node.appendChild(create_filter_node(filter_id, filter_info, filter));
 
1475
        node.append(create_filter_node(filter_id, filter_info, filter));
1428
1476
        filter_id += 1;
1429
1477
    }
1430
1478
    return node;
1641
1689
    var team_info = get_team_info(form_data);
1642
1690
 
1643
1691
    var filter_info = {
1644
 
        filter : filter,
 
1692
        filter: filter,
1645
1693
        subscriber_is_team: team_info.is_team,
1646
1694
        user_is_team_admin: team_info.is_team,
1647
1695
        can_mute: team_info.is_team,