Changeset 694

Show
Ignore:
Timestamp:
06/05/08 04:01:41 (18 months ago)
Author:
mpaschal
Message:

Filter action list by service

Location:
trunk/ActionStreams/plugins/ActionStreams
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/ActionStreams/plugins/ActionStreams/lib/ActionStreams/Plugin.pm

    r691 r694  
    116116    my %params = map { $_ => $app->param($_) ? 1 : 0 } 
    117117        qw( saved_deleted hidden shown ); 
     118 
     119    $params{services} = []; 
     120    my $services = $app->registry('profile_services'); 
     121    while (my ($prevt, $service) = each %$services) { 
     122        push @{ $params{services} }, { 
     123            service_id   => $prevt, 
     124            service_name => $service->{name}, 
     125        }; 
     126    } 
     127    $params{services} = [ sort { lc $a->{service_name} cmp lc $b->{service_name} } @{ $params{services} } ]; 
     128 
     129    my %terms = ( 
     130        class => '*', 
     131        author_id => $author_id, 
     132    ); 
     133    my %args = ( 
     134        sort => 'created_on', 
     135        direction => 'descend', 
     136    ); 
     137 
     138    if (my $filter = $app->param('filter')) { 
     139        $params{filter_key} = $filter; 
     140        my $filter_val = $params{filter_val} = $app->param('filter_val'); 
     141        $params{filter_label} = 'Actions from the service ' . $app->registry('profile_services')->{$filter_val}->{name}; 
     142        if ($filter eq 'service') { 
     143            $terms{class} = $filter_val . '_%'; 
     144            $args{like} = { class => 1 }; 
     145        } 
     146    } 
     147 
    118148    $params{id} = $params{edit_author_id} = $author_id; 
    119149    $params{service_styles} = \@service_styles_loop; 
    120150    $app->listing({ 
    121151        type     => 'profileevent', 
    122         terms    => { 
    123             class     => '*', 
    124             author_id => $author_id, 
    125         }, 
    126         args     => { 
    127             sort      => 'created_on', 
    128             direction => 'descend', 
    129         }, 
     152        terms    => \%terms, 
     153        args     => \%args, 
    130154        listing_screen => 1, 
    131155        code     => $code, 
  • trunk/ActionStreams/plugins/ActionStreams/tmpl/list_profileevent.tmpl

    r471 r694  
    2525        return doForMarkedInThisWindow(f, '', 'profileevents', 'id', 'itemset_action', 
    2626            {'action_name': action}, 'to act upon'); 
     27    } 
     28 
     29    function toggleFilter() { 
     30        var filterActive = getByID("filter-title"); 
     31        if (filterActive.style.display == "none") { 
     32            filterActive.style.display = "block"; 
     33            getByID("filter-select").style.display = "none"; 
     34        } else { 
     35            filterActive.style.display = "none"; 
     36            getByID("filter-select").style.display = "block"; 
     37            <mt:unless name="filter">setFilterCol('status');</mt:unless> 
     38        } 
     39    } 
     40 
     41    function setFilterCol(choice) { 
     42        var sel = getByID('filter-select'); 
     43        if (!sel) return; 
     44        sel.className = "filter-" + choice; 
     45        if (choice != 'none') { 
     46            var fld = getByID('filter-col'); 
     47            if (choice == 'status') 
     48                fld.selectedIndex = 0; 
     49            else if (choice == 'author_id') 
     50                fld.selectedIndex = 1; 
     51            else if (choice == 'exacttag') 
     52                fld.selectedIndex = 2; 
     53            else if (choice == 'normalizedtag') 
     54                fld.selectedIndex = 3; 
     55            else if (choice == 'category_id') 
     56                fld.selectedIndex = 4; 
     57            else if (choice == 'asset_id') 
     58                fld.selectedIndex = <mt:if name="category_loop">5<mt:else>4</mt:if>; 
     59            col_span = getByID("filter-text-col"); 
     60            if (fld.selectedIndex > -1 && col_span) 
     61                col_span.innerHTML = '<strong>' + fld.options[fld.selectedIndex].text + '</strong>'; 
     62        } 
     63    } 
     64 
     65   function enableFilterButton(fld) { 
     66        if (fld && (fld.id == "author_id-val" || fld.id == "asset_id-val")) { 
     67            var opt = fld.options[fld.selectedIndex]; 
     68            if (opt.id == 'filter-user-search') { 
     69    <mt:if name="object_type" eq="entry"> 
     70                window.location = ScriptURI + '?__mode=search_replace&_type=author&entry_type=entry'; 
     71    <mt:else> 
     72                window.location = ScriptURI + '?__mode=search_replace&_type=author&entry_type=page'; 
     73    </mt:if> 
     74            } 
     75            else if (opt.id == 'filter-asset-search') { 
     76                window.location = ScriptURI + '?__mode=search_replace&_type=asset'; 
     77            } 
     78            else { 
     79                if (opt.value == "") { 
     80                    getByID("filter-button").style.display = "none"; 
     81                    return; 
     82                } 
     83            } 
     84        } else if (fld && (fld.id == "filter-col")) { 
     85            var opt = fld.options[fld.selectedIndex]; 
     86            if (opt.value == 'author_id') { 
     87                var authfld = getByID("author_id-val"); 
     88                var authopt = authfld.options[authfld.selectedIndex]; 
     89                if (authopt.value == "") { 
     90                    getByID("filter-button").style.display = "none"; 
     91                    return; 
     92                } 
     93            } 
     94        } 
     95        getByID("filter-button").style.display = "inline"; 
    2796    } 
    2897 
     
    104173 
    105174<mt:include name="include/header.tmpl"> 
     175 
     176<div class="listing-filter"> 
     177    <div class="listing-filter-inner inner pkg"> 
     178<form id="filter-form" method="get" action="<mt:var name="mt_url">"> 
     179    <input type="hidden" name="__mode" value="<mt:var name="mode">" /> 
     180    <mt:if name="id"> 
     181    <input type="hidden" name="id" value="<mt:var name="id">" /> 
     182    </mt:if> 
     183    <mt:if name="is_power_edit"> 
     184    <input type="hidden" name="is_power_edit" value="1" /> 
     185    </mt:if> 
     186    <input id="filter" type="hidden" name="filter" value="" /> 
     187    <input id="filter_val" type="hidden" name="filter_val" value="" /> 
     188</form> 
     189<form id="filter-select-form" method="get" onsubmit="return execFilter(this)"> 
     190    <div class="filter"> 
     191        <div id="filter-title"> 
     192            <mt:if name="filter_key"> 
     193                <strong>Showing only: <mt:var name="filter_label" escape="html"></strong> 
     194                <a class="filter-link" href="<mt:var name="script_url">?__mode=<mt:var name="mode">&amp;id=<mt:var name="id">">[ Remove filter ]</a> 
     195            <mt:else> 
     196                <mt:if name="filter"> 
     197                <mt:else> 
     198                    <strong>All stream actions</strong> 
     199                    <a class="filter-link" href="javascript:void(0)" onclick="toggleFilter()">[ change ]</a> 
     200                </mt:if> 
     201            </mt:if> 
     202        </div> 
     203        <div id="filter-select" class="page-title" style="display: none"> 
     204            Show only actions where 
     205            <select id="filter-col" name="filter" onchange="setFilterCol(this.options[this.selectedIndex].value); enableFilterButton(this)"> 
     206                <!-- option value="stream">stream</option --> 
     207                <option value="service">service</option> 
     208            </select> 
     209            is 
     210            <span id="filter-service"> 
     211                <select id="service-val" name="filter_val" onchange="enableFilterButton()"> 
     212                    <mt:loop name="services"> 
     213                        <option value="<mt:var name="service_id">"><mt:var name="service_name"></option> 
     214                    </mt:loop> 
     215                </select> 
     216            </span> 
     217 
     218            <span class="buttons"> 
     219                <a href="javascript:void(0)" 
     220                    id="filter-button" 
     221                    onclick="return execFilter(getByID('filter-select-form'))" 
     222                    type="submit" 
     223                    >Filter</a> 
     224                <a href="javascript:void(0)" 
     225                    onclick="toggleFilter(); return false" 
     226                    type="submit" 
     227                    >Cancel</a> 
     228            </span> 
     229        </div> 
     230    </div> 
     231</form> 
     232    </div> 
     233</div> 
    106234 
    107235<mtapp:listing type="profileevent" default="<__trans phrase="No events could be found.">" empty_message="<__trans phrase="No events could be found.">">