Bug 9021 [QA Followup] - Add feedback to delete button if provider is being used
authorKyle M Hall <kyle@bywatersolutions.com>
Wed, 10 Feb 2016 10:19:00 +0000 (10:19 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Sun, 14 Feb 2016 12:40:07 +0000 (12:40 +0000)
* Change links to buttons
* Add warning class to delete button if provider is being used

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Koha/SMS/Provider.pm
koha-tmpl/intranet-tmpl/prog/en/modules/admin/sms_providers.tt

index 1aa70dc..cc047dd 100644 (file)
@@ -21,6 +21,8 @@ use Modern::Perl;
 
 use Carp;
 
+use Koha::Borrowers;
+
 use base qw(Koha::Object);
 
 =head1 NAME
@@ -34,6 +36,20 @@ Koha::SMS::Provider - Koha SMS Provider object class
 
 =cut
 
+=head3 patrons_using
+
+my $count = $provider->patrons_using()
+
+Gives the number of patrons using this provider
+
+=cut
+
+sub patrons_using {
+    my ( $self ) = @_;
+
+    return Koha::Borrowers->search( { sms_provider_id => $self->id } )->count();
+}
+
 =head3 type
 
 =cut
index c33f216..706db5c 100644 (file)
@@ -60,6 +60,7 @@ function delete_provider( id ) {
                         <tr>
                             <th>Name</th>
                             <th>Domain</th>
+                            <th title="Patrons using this provider">Patrons</th>
                             <th>&nbsp;</th>
                             <th>&nbsp;</th>
                         </tr>
@@ -70,8 +71,23 @@ function delete_provider( id ) {
                             <tr>
                                 <td id="name_[% p.id %]">[% p.name %]</td>
                                 <td id="domain_[% p.id %]">[% p.domain %]</td>
-                                <td><a href="#" id="edit_[% p.id %]" class="edit" onclick="edit_provider( [% p.id %] );">Edit</td>
-                                <td><a href="#" id="delete_[% p.id %]" class="delete" onclick="delete_provider( [% p.id %] );">Delete</td>
+                                <td id="patrons_using_[% p.id %]">[% p.patrons_using %]</td>
+                                <td>
+                                    <a class="btn" href="#" id="edit_[% p.id %]" class="edit" onclick="edit_provider( [% p.id %] );">
+                                        <i class="fa fa-pencil"></i> Edit
+                                    </a>
+                                </td>
+                                <td>
+                                    [% IF p.patrons_using %]
+                                        <a class="btn btn-danger" href="#" id="delete_[% p.id %]" class="delete" onclick="delete_provider( [% p.id %] );">
+                                            <span style="color:white"><i class="fa fa-trash"></i> Delete</span>
+                                        </a>
+                                    [% ELSE %]
+                                        <a class="btn" href="#" id="delete_[% p.id %]" class="delete" onclick="delete_provider( [% p.id %] );">
+                                            <i class="fa fa-trash"></i> Delete
+                                        </a>
+                                    [% END %]
+                                </td>
                             </tr>
                         [% END %]
                     </tbody>
@@ -83,11 +99,19 @@ function delete_provider( id ) {
                             <tr>
                                 <td><input type="text" id="name" name="name" /></td>
                                 <td><input type="text" id="domain" name="domain" size="40"/></td>
+                                <td colspan="2">
+                                    <button class="btn" id="submit_save" type="submit">
+                                        <i class="fa fa-plus"></i> Add new
+                                    </button>
+                                    <button class="btn" id="submit_update" type="submit">
+                                        <i class="fa fa-plus-circle"></i> Update
+                                    </button>
+                                </td>
                                 <td>
-                                    <input id="submit_save" type="submit" value="Add new">
-                                    <input id="submit_update" type="submit" value="Update">
+                                    <a class="btn" id="cancel" href="#" onclick="cancel_edit()">
+                                        <i class="fa fa-ban"></i> Cancel
+                                    </a>
                                 </td>
-                                <td><a id="cancel" href="#" onclick="cancel_edit()">Cancel</a></td>
                             </tr>
                         </form>
                     </tfoot>