@@ -3,25 +3,26 @@ import _ from "underscore";
33import PopoverView from "../../../../core/ui/views/popover" ;
44import utils from "../../../../core/utils" ;
55import ItemTemplate from "../../templates/selection_item.xml" ;
6+ import Actions from "../actions" ;
7+ import _t from "../../../../core/i18n-wrapper" ;
68
79export default PopoverView . extend ( {
8- className : "popover selected-items " ,
10+ className : "popover change-selection " ,
911
10- title : _ . template (
11- '<input type="text" class="filter" placeholder="<%- _t("Filter") %>" />' +
12- '<a href="#" class=" remove-all">' +
13- '<%= removeIcon %> <%- _t("remove all") %></a>'
14- ) ,
12+
13+ title : _t ( "Manage selection" ) ,
1514
1615 content : _ . template (
17- "<% collection.each(function(item) { %>" +
18- "<%= item_template($.extend({'removeIcon': removeIcon}, item.toJSON())) %>" +
19- "<% }); %>"
16+ '<div class="list-group">' +
17+ '<a href="#" class="list-group-item list-group-item-action select-all"><%= selectAllIcon %> <%- _t("Select all items in the folder") %></a>' +
18+ '<a href="#" class="list-group-item list-group-item-action select-all-visible"><%= selectPageIcon %> <%- _t("Select all items on this page") %></a>' +
19+ '<a href="#" class="list-group-item list-group-item-action remove-all"><%= removeIcon %> <%- _t("Cancel selection") %></a>' +
20+ '</div>'
2021 ) ,
2122
2223 events : {
23- "click a.remove " : "itemRemoved " ,
24- "keyup input.filter " : "filterSelected " ,
24+ "click .select-all " : "selectAll " ,
25+ "click .select-all-visible " : "selectVisible " ,
2526 "click .remove-all" : "removeAll" ,
2627 } ,
2728
@@ -39,35 +40,33 @@ export default PopoverView.extend({
3940
4041 render : async function ( ) {
4142 this . options [ "removeIcon" ] = await utils . resolveIcon ( "x-circle" ) ;
43+ this . options [ "selectAllIcon" ] = await utils . resolveIcon ( "check2-all" ) ;
44+ this . options [ "selectPageIcon" ] = await utils . resolveIcon ( "check2" ) ;
4245 PopoverView . prototype . render . call ( this ) ;
4346 if ( this . collection . length === 0 ) {
4447 this . $el . removeClass ( "active" ) ;
4548 }
4649 return this ;
4750 } ,
48-
49- itemRemoved : function ( e ) {
50- e . preventDefault ( ) ;
51- const uid = $ ( e . currentTarget ) . data ( "uid" ) ;
52- this . collection . removeByUID ( uid ) ;
53- if ( this . collection . length !== 0 ) {
54- // re-rendering causes it to close, reopen
55- this . show ( ) ;
56- }
51+ selectAll : function ( e ) {
52+ // use the actions module as it has a handy "selectAll" method
53+ const actions = new Actions ( {
54+ app : this . options . app ,
55+ model : {
56+ attributes : this . options . app . options ,
57+ } ,
58+ selectedCollection : this . options . collection ,
59+ } ) ;
60+ actions . selectAll ( e ) ;
61+ this . options . app . tableView . setContextInfo ( ) ;
62+ this . hide ( ) ;
5763 } ,
58-
59- filterSelected : function ( e ) {
60- const val = $ ( e . target ) . val ( ) . toLowerCase ( ) ;
61- for ( const item of $ ( ".selected-item" , this . $el ) ) {
62- const $el = $ ( item ) ;
63- if ( $el . text ( ) . toLowerCase ( ) . indexOf ( val ) === - 1 ) {
64- $el . hide ( ) ;
65- } else {
66- $el . show ( ) ;
67- }
68- }
64+ selectVisible : function ( e ) {
65+ e . preventDefault ( ) ;
66+ this . collection . reset ( ) ;
67+ $ ( 'input[type="checkbox"]' , this . app . tableView . $ ( 'tbody' ) ) . prop ( 'checked' , true ) . change ( ) ;
68+ this . hide ( ) ;
6969 } ,
70-
7170 removeAll : function ( e ) {
7271 e . preventDefault ( ) ;
7372 this . collection . reset ( ) ;
0 commit comments