View | Details | Raw Unified | Return to bug 15326
Collapse All | Expand All

(-)a/Koha/CmsPages.pm (-43 / +24 lines)
Lines 49-97 sub object_class { Link Here
49
}
49
}
50
50
51
=head3 add
51
=head3 add
52
52
Adds a new page to the CMS database based on the input data.
53
Adds a new page to the CMS database based on the input data.
54
53
=cut
55
=cut
54
56
55
sub add {
57
sub add {
56
    my ( $self, $input ) = @_;
58
    my ( $self, $input ) = @_;
57
    carp( 'Koha::CmsPages::add() undefined parameter: input' ) unless defined $input;
59
    carp( 'Koha::CmsPages::add() undefined parameter: input' ) unless defined $input;
60
58
    my $data = {
61
    my $data = {
59
        parent     =>   scalar          $input->param( 'parent' ) eq '' ? undef : scalar $input->param( 'parent' ),
62
        parent     => $input->{parent},
60
        location   =>   scalar          $input->param( 'disp' )   eq '' ? undef : scalar $input->param( 'disp'),
63
        location   => $input->{location},
61
        branchcode =>   scalar          $input->param( 'branch' ) eq '' ? undef : scalar $input->param( 'branch' ),
64
        branchcode => $input->{branchcode},
62
        lang       =>   scalar          $input->param( 'lang' ),
65
        lang       => $input->{lang},
63
        sortorder  =>   scalar          $input->param( 'number' ),
66
        sortorder  => $input->{sortorder},
64
        title      =>   scalar          $input->param( 'title' ),
67
        title      => $input->{title},
65
        title_link =>   scalar          $input->param( 'title_link' ),
68
        title_link => $input->{title_link},
66
        publish    =>   defined (scalar $input->param( 'publish' )),
69
        publish    => $input->{publish},
67
        content    =>   scalar          $input->param( 'content' )
70
        content    => $input->{content}
68
    };
71
    };
69
72
70
    if (defined $input->param( 'id' )) {
73
    if (defined $input->{id}){
71
        $data->{'id'} = scalar $input->param( 'id' );
74
        $data->{id} = $input->{id};
72
    }
75
    }
73
76
74
    # Ensuring link titles are unique
77
    # Ensuring link titles are unique
75
    my $title_link = $input->param('title_link');
78
    my $title_link = $input->{title_link};
76
    if ( Koha::CmsPages->find({ title_link => $title_link }) ) {
79
    if ( Koha::CmsPages->find({ title_link => $title_link }) ){
77
        my $existing_link = Koha::CmsPages->find({ title_link => $title_link });
80
        my $link = Koha::CmsPages->find({ title_link => $title_link });
78
        my $link = $existing_link->unblessed;
81
        unless ( $link->id eq $input->{id} ){
79
        unless ( $link->{'id'} eq $input->param('id') ) {
82
            return;
80
            return undef;
81
        }
83
        }
82
    }
84
    }
83
85
84
    # Ensuring that, if page has parent, provided location suits parent location
86
    # Ensuring that, if page has parent, provided location suits parent location
85
    my $parent = $input->param('parent');
87
    my $parent = Koha::CmsPages->find($input->{parent});
86
    my $parent_obj = Koha::CmsPages->find($parent);
88
    if ( $parent && $parent->location ne "" ){
87
    if ( $parent_obj ) {
89
        if ( $parent->location ne $input->{location} ){
88
        my $parent_unblessed = $parent_obj->unblessed;
90
            return;
89
        if ( $parent_unblessed->{'location'} ne "" ) {
90
            # if parent location is not all interfaces
91
            if ( $parent_unblessed->{'location'} != $input->param('disp') ) {
92
                # if parent location is not the same as provided location
93
                return undef;
94
            }
95
        }
91
        }
96
    }
92
    }
97
93
Lines 102-108 sub add { Link Here
102
98
103
=head3 list
99
=head3 list
104
100
105
Lists pages based input filtering paramters for location, branch and language.
101
Lists pages based input filtering parameters for location, branch and language.
106
102
107
=cut
103
=cut
108
104
Lines 199-219 sub child_links { Link Here
199
    return $rs;
195
    return $rs;
200
}
196
}
201
197
202
=head3 remove
203
204
Removes a page identified by id from the CMS database.
205
206
=cut
207
208
sub remove {
209
    my ( $self, @ids ) = @_;
210
211
    carp( 'Koha::CmsPages::remove() undefined parameter ids' ) unless @ids;
212
213
    my $pages = $self->_resultset()->search({ id => \@ids });
214
    $pages->delete;
215
}
216
217
=head1 AUTHOR
198
=head1 AUTHOR
218
199
219
Martin Persson <xarragon@gmail.com>
200
Martin Persson <xarragon@gmail.com>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cmspages.tt (-14 / +29 lines)
Lines 9-16 Link Here
9
[% INCLUDE 'datatables.inc' %]
9
[% INCLUDE 'datatables.inc' %]
10
<script type="text/javascript" src="[% interface %]/lib/tiny_mce/tiny_mce.js"></script>
10
<script type="text/javascript" src="[% interface %]/lib/tiny_mce/tiny_mce.js"></script>
11
<script type="text/javascript">//<![CDATA[
11
<script type="text/javascript">//<![CDATA[
12
var MSG_CONFIRM_DELETE_PAGE  = _("Are you sure you want to delete the selected page(s)?");
13
14
$(document).ready(function() {
12
$(document).ready(function() {
15
    $("#pages_table").dataTable($.extend(true, {}, dataTablesDefaults, {
13
    $("#pages_table").dataTable($.extend(true, {}, dataTablesDefaults, {
16
        "aoColumnDefs": [
14
        "aoColumnDefs": [
Lines 20-26 $(document).ready(function() { Link Here
20
    }));
18
    }));
21
19
22
    $("#del_button").on("click",function(){
20
    $("#del_button").on("click",function(){
23
        return confirmDelete(MSG_CONFIRM_DELETE_PAGE);
21
        if ($("input[name='ids'][type='checkbox']:checked").length){
22
            return confirmDelete(_("Are you sure you want to delete the selected page(s)?"));
23
        } else {
24
            alert(_("No pages have been selected."));
25
            return false;
26
        }
27
    });
28
29
    $(".del_single").on("click", function(){
30
        return confirmDelete(_("Are you sure you want to delete this page?"));
24
    });
31
    });
25
32
26
    $(".SelectAll").on("click", function(){
33
    $(".SelectAll").on("click", function(){
Lines 89-95 tinyMCE.init({ Link Here
89
[% END %]
96
[% END %]
90
[% UNLESS ( form || view ) %]
97
[% UNLESS ( form || view ) %]
91
<div id="toolbar" class="btn-toolbar">
98
<div id="toolbar" class="btn-toolbar">
92
    <a class="btn btn-small" id="newentry" href="[% link_self %]?op=form"><i class="fa fa-plus"></i> New page</a>
99
    <a class="btn btn-default btn-sm" id="newentry" href="[% link_self %]?op=form"><i class="fa fa-plus"></i> New page</a>
93
</div>
100
</div>
94
[% END %]
101
[% END %]
95
[% IF ( failed_add ) %]
102
[% IF ( failed_add ) %]
Lines 252-258 tinyMCE.init({ Link Here
252
                        <th>Number</th>
259
                        <th>Number</th>
253
                        <th>Link title</th>
260
                        <th>Link title</th>
254
                        <th>Page title</th>
261
                        <th>Page title</th>
255
                        <th>Actions</th>
262
                        <th>&nbsp;</th>
256
                    </tr></thead>
263
                    </tr></thead>
257
                    <tbody>[% FOREACH page IN page_list %]
264
                    <tbody>[% FOREACH page IN page_list %]
258
                        <tr>
265
                        <tr>
Lines 278-292 tinyMCE.init({ Link Here
278
                            <td><a href="[% link_self %]?op=form&amp;id=[% page.id %]">[% page.title_link %]</a></td>
285
                            <td><a href="[% link_self %]?op=form&amp;id=[% page.id %]">[% page.title_link %]</a></td>
279
                            <td>[% page.title %]</td>
286
                            <td>[% page.title %]</td>
280
                            <td class="actions">
287
                            <td class="actions">
281
                                <a href="[% link_self %]?op=form&amp;id=[% page.id %]" class="btn btn-mini"><i class="fa fa-pencil"></i> Edit</a>
288
                                <div class="btn-group">
282
                                [% IF ( page.location == "" ) %]
289
                                    <a class="btn btn-default btn-xs dropdown-toggle" id="opencmspageactions[% page.id %]" role="button" data-toggle="dropdown" href="#">
283
                                    <a href="[% link_opac %]?id=[% page.id %]" class="btn btn-mini"><i class="fa fa-eye"></i> OPAC</a>
290
                                        Actions <b class="caret"></b></a>
284
                                    <a href="[% link_self %]?op=view&amp;id=[% page.id %]" class="btn btn-mini"><i class="fa fa-eye"></i> Intranet</a>
291
                                    <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="opencmspageactions[% page.id %]">
285
                                [% ELSIF ( page.location == "1" ) %]
292
                                        <li><a href="[% link_self %]?op=form&amp;id=[% page.id %]"><i class="fa fa-pencil"></i> Edit</a></li>
286
                                    <a href="[% link_self %]?op=view&amp;id=[% page.id %]" class="btn btn-mini"><i class="fa fa-eye"></i> Intranet</a>
293
                                        <li><a href="[% link_self %]?op=delSingle&amp;id=[% page.id %]" class="del_single"><i class="fa fa-trash"></i> Delete</a></li>
287
                                [% ELSIF ( page.location == "2" ) %]
294
                                        [% IF ( page.location == "" ) %]
288
                                    <a href="[% link_opac %]?id=[% page.id %]" class="btn btn-mini"><i class="fa fa-eye"></i> OPAC</a>
295
                                            <li><a href="[% link_opac %]?id=[% page.id %]"><i class="fa fa-eye"></i> OPAC</a></li>
289
                                [% END %]
296
                                            <li><a href="[% link_self %]?op=view&amp;id=[% page.id %]"><i class="fa fa-eye"></i> Intranet</a></li>
297
                                        [% ELSIF ( page.location == "1" ) %]
298
                                            <li><a href="[% link_self %]?op=view&amp;id=[% page.id %]"><i class="fa fa-eye"></i> Intranet</a></li>
299
                                        [% ELSIF ( page.location == "2" ) %]
300
                                            <li><a href="[% link_opac %]?id=[% page.id %]"><i class="fa fa-eye"></i> OPAC</a></li>
301
                                        [% END %]
302
                                    </ul>
303
                                </div>
304
                            </td>
290
                        </tr>
305
                        </tr>
291
                    [% END %]</tbody>
306
                    [% END %]</tbody>
292
                </table>
307
                </table>
(-)a/t/db_dependent/Pages.t (-51 / +72 lines)
Lines 18-92 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 2;
21
use Test::More tests => 10;
22
use Test::Warn;
22
use Test::Warn;
23
use Data::Dumper::Concise;
24
23
25
use C4::Context;
24
use C4::Context;
26
use Koha::Database;
25
use Koha::Database;
27
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
28
27
29
BEGIN {
28
BEGIN {
30
    use_ok('Koha::Objects');
31
    use_ok('Koha::CmsPages');
29
    use_ok('Koha::CmsPages');
30
    use_ok('Koha::CmsPage');
32
}
31
}
33
32
34
my $builder = t::lib::TestBuilder->new();
33
my $database = Koha::Database->new();
34
my $schema   = $database->schema();
35
my $dbh      = C4::Context->dbh;
36
my $builder  = t::lib::TestBuilder->new();
35
37
36
# Start transaction
38
$schema->storage->txn_begin();
37
my $dbh = C4::Context->dbh;
39
$dbh->do( 'DELETE FROM cms_pages' );
38
$dbh->{ AutoCommit } = 0;
40
$dbh->do( 'DELETE FROM issues' );
39
$dbh->{ RaiseError } = 1;
40
$dbh->do( 'DELETE FROM items' );
41
$dbh->do( 'DELETE FROM borrowers' );
41
$dbh->do( 'DELETE FROM borrowers' );
42
$dbh->do( 'DELETE FROM items' );
42
$dbh->do( 'DELETE FROM branches' );
43
$dbh->do( 'DELETE FROM branches' );
43
$dbh->do( 'DELETE FROM cms_pages' );
44
44
45
my $branchcode = $builder->build({ source => 'Branch' });
45
my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'};
46
46
my $borrowernumber = $builder->build({ source => 'Borrower' })->{'borrowernumber'};
47
my $page10 = $builder->build({
47
48
	source => 'CmsPage',
48
# new parent page
49
	value  => {
49
my $parent_page = Koha::CmsPages->add({
50
		parent     => undef,
50
    id => 1,
51
		title_link => 'page 10',
51
    branchcode => $branchcode,
52
		title      => 'full page 10',
52
    location => 2,
53
		published  => 1,
53
    lang => '',
54
		sortorder  => 1,
54
    parent => undef,
55
	}
55
    title_link => 'page1',
56
});
56
    title => 'Page 1',
57
my $page11 = $builder->build({
57
    publish => 0,
58
	source => 'CmsPage',
58
    sortorder => 1,
59
	value  => {
59
    content => "This is the first page.",
60
		parent     => $page10->{'id'},
61
		title_link => 'subpage 11',
62
		title      => 'full subpage 11',
63
		published  => 1,
64
		sortorder  => 0,
65
	}
66
});
60
});
67
my $page12 = $builder->build({
61
68
	source => 'CmsPage',
62
is($parent_page->title, 'Page 1', "First page created");
69
	value  => {
63
70
		parent     => $page10->{'id'},
64
# new child page
71
		title_link => 'subpage 12',
65
my $child_page = Koha::CmsPages->add({
72
		title      => 'full subpage 12',
66
    id => 2,
73
		published  => 1,
67
    branchcode => $branchcode,
74
		sortorder  => 1,
68
    location => 2,
75
	}
69
    lang => '',
70
    parent => $parent_page->id,
71
    title_link => 'page2',
72
    title => 'Page 2',
73
    publish => 1,
74
    sortorder => 2,
75
    content => "This is the second page.",
76
});
76
});
77
my $page20 = $builder->build({
77
78
	source => 'CmsPage',
78
# $page->parent specifies who this page is the parent of
79
	value  => {
79
is(Koha::CmsPages->find($child_page->parent)->title, 'Page 1', 'Child and parent page connected');
80
		parent     => undef,
80
81
		title_link => 'page 20',
81
# Koha::CmsPages->list() with no specified ID should return all pages
82
		title      => 'full page 20',
82
my ( $page_list, $parent_list, $data ) = Koha::CmsPages->list( '' );
83
		published  => 0,
83
is(scalar @{ $page_list }, 2, "Two pages have been created");
84
		sortorder  => 2,
84
85
	}
85
# Koha::CmsPages->list() is used for filtering (filter display location)
86
( $page_list, $parent_list, $data ) = Koha::CmsPages->list( '', 2, '', '' );
87
is(scalar @{ $page_list }, 2, "Both pages can be seen on staff interface");
88
89
is($parent_list->[0]->{id}, $parent_page->id, "Correct page is returned as a parent");
90
is($data, undef, "Data is undefined because no ID was given");
91
92
# Koha::CmsPages->list() is used to show data about a page when given an ID
93
( $page_list, $parent_list, $data ) = Koha::CmsPages->list( 2 );
94
is($data->{content}, "This is the second page.", "Data is defined when given an ID");
95
96
# Try to add a child page under a page where their locations do not match up
97
my $test_page = Koha::CmsPages->add({
98
    id => 3,
99
    branchcode => $branchcode,
100
    location => 1,
101
    lang => '',
102
    parent => $child_page->id,
103
    title_link => 'failedadd',
104
    title => 'Failed add',
105
    publish => 0,
106
    sortorder => 3,
107
    content => "This page should not be added",
86
});
108
});
87
109
88
my $result = Koha::CmsPages->child_links( undef );
110
is($test_page, undef, "Child page cannot be added under a page if their locations do not match");
89
is_deeply( $result, [ $page10, $page20 ]);
90
111
91
$dbh->rollback();
112
$dbh->rollback();
92
113
(-)a/tools/cmspages.pl (-3 / +20 lines)
Lines 25-30 use C4::Output; Link Here
25
use C4::Languages qw( getTranslatedLanguages );
25
use C4::Languages qw( getTranslatedLanguages );
26
use Koha::CmsPages;
26
use Koha::CmsPages;
27
use Koha::Libraries;
27
use Koha::Libraries;
28
use Koha::CmsPage;
28
29
29
my $link_self = '/cgi-bin/koha/tools/cmspages.pl';
30
my $link_self = '/cgi-bin/koha/tools/cmspages.pl';
30
31
Lines 72-87 if ( $op eq 'form' ) { Link Here
72
        op   => 'add'
73
        op   => 'add'
73
    );
74
    );
74
} elsif ( $op eq 'add' ) {
75
} elsif ( $op eq 'add' ) {
75
    my $success = Koha::CmsPages->add( $cgi );
76
    my $success = Koha::CmsPages->add({
77
        id         => scalar $cgi->param('id'),
78
        parent     => scalar $cgi->param('parent'),
79
        location   => scalar $cgi->param('disp'),
80
        branchcode => scalar $cgi->param('branch'),
81
        lang       => scalar $cgi->param('lang'),
82
        sortorder  => scalar $cgi->param('number'),
83
        title      => scalar $cgi->param('title'),
84
        title_link => scalar $cgi->param('title_link'),
85
        publish    => scalar $cgi->param('publish'),
86
        content    => scalar $cgi->param('content'),
87
    });
76
    unless ($success) {
88
    unless ($success) {
77
        $template->param( failed_add => 1 );
89
        $template->param( failed_add => 1 );
78
    }
90
    }
79
    if ($success) {
91
    if ($success) {
80
        print $cgi->redirect( $link_self );
92
        print $cgi->redirect( $link_self );
81
    }
93
    }
94
} elsif ( $op eq 'delSingle' ) {
95
    Koha::CmsPages->find( $id )->delete();
96
    print $cgi->redirect( $link_self );
82
} elsif ( $op eq 'del' ) {
97
} elsif ( $op eq 'del' ) {
83
    # param => multi_param; no list-ctx warnings
98
    # param => multi_param; no list-ctx warnings
84
    Koha::CmsPages->remove( $cgi->multi_param( 'ids' ) );
99
    my @ids = $cgi->multi_param('ids');
100
    foreach (@ids){
101
        Koha::CmsPages->find($_)->delete;
102
    }
85
    print $cgi->redirect( $link_self );
103
    print $cgi->redirect( $link_self );
86
} elsif ( $op eq 'view' ) {
104
} elsif ( $op eq 'view' ) {
87
    my $cms_data = Koha::CmsPages->page( $id );
105
    my $cms_data = Koha::CmsPages->page( $id );
88
- 

Return to bug 15326