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

(-)a/C4/Items.pm (-3 / +3 lines)
Lines 3099-3105 sub ToggleNewStatus { Link Here
3099
    my @biblioitem_columns = map { "biblioitems.$_" } C4::Items::biblioitems_columns;
3099
    my @biblioitem_columns = map { "biblioitems.$_" } C4::Items::biblioitems_columns;
3100
    my $report;
3100
    my $report;
3101
    for my $rule ( @rules ) {
3101
    for my $rule ( @rules ) {
3102
        my $duration = $rule->{duration};
3102
        my $age = $rule->{age};
3103
        my $conditions = $rule->{conditions};
3103
        my $conditions = $rule->{conditions};
3104
        my $substitutions = $rule->{substitutions};
3104
        my $substitutions = $rule->{substitutions};
3105
        my @params;
3105
        my @params;
Lines 3127-3135 sub ToggleNewStatus { Link Here
3127
                }
3127
                }
3128
            }
3128
            }
3129
        }
3129
        }
3130
        if ( defined $duration ) {
3130
        if ( defined $age ) {
3131
            $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |;
3131
            $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |;
3132
            push @params, $duration;
3132
            push @params, $age;
3133
        }
3133
        }
3134
        my $sth = $dbh->prepare($query);
3134
        my $sth = $dbh->prepare($query);
3135
        $sth->execute( @params );
3135
        $sth->execute( @params );
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt (-12 / +12 lines)
Lines 65-71 Link Here
65
      $(new_rule).find("select[name='substitution_field']").attr('name', 'substitution_field_' + unique_id);
65
      $(new_rule).find("select[name='substitution_field']").attr('name', 'substitution_field_' + unique_id);
66
      $(new_rule).find("input[name='condition_value']").attr('name', 'condition_value_' + unique_id);
66
      $(new_rule).find("input[name='condition_value']").attr('name', 'condition_value_' + unique_id);
67
      $(new_rule).find("input[name='substitution_value']").attr('name', 'substitution_value_' + unique_id);
67
      $(new_rule).find("input[name='substitution_value']").attr('name', 'substitution_value_' + unique_id);
68
      $(new_rule).find("input[name='duration']").attr('name', 'duration_' + unique_id);
68
      $(new_rule).find("input[name='age']").attr('name', 'age_' + unique_id);
69
      $(new_rule).find("input[name='unique_id']").val(unique_id);
69
      $(new_rule).find("input[name='unique_id']").val(unique_id);
70
70
71
      $("#rules").append(new_rule);
71
      $("#rules").append(new_rule);
Lines 145-153 Link Here
145
                  [% SET id = loop.count %]
145
                  [% SET id = loop.count %]
146
                  <div class="rule">
146
                  <div class="rule">
147
                    <input type="hidden" name="unique_id" value="[% loop.count %]" /> <!-- FIXME on update, the unique_id should be filled -->
147
                    <input type="hidden" name="unique_id" value="[% loop.count %]" /> <!-- FIXME on update, the unique_id should be filled -->
148
                    <div class="duration">
148
                    <div class="age">
149
                      <h5>Duration</h5>
149
                      <h5>Age</h5>
150
                      <input type="text" value="[% rule.duration %]" name="duration_[% id %]" /> days
150
                      <input type="type" value="[% rule.age %]" name="age_[% id %]" /> days
151
                    </div>
151
                    </div>
152
                    <div class="blocks">
152
                    <div class="blocks">
153
                      <h5>Conditions</h5>
153
                      <h5>Conditions</h5>
Lines 208-216 Link Here
208
          <h4>Add a new rule</h4>
208
          <h4>Add a new rule</h4>
209
          <div id="new_rule">
209
          <div id="new_rule">
210
            <input type="hidden" name="unique_id" />
210
            <input type="hidden" name="unique_id" />
211
            <div class="duration">
211
            <div class="age">
212
              <h5>Duration</h5>
212
              <h5>Age</h5>
213
              <input type="text" value="" name="duration" /> days
213
              <input type="text" value="" name="age" /> days
214
            </div>
214
            </div>
215
            <div class="blocks">
215
            <div class="blocks">
216
              <h5>Conditions</h5>
216
              <h5>Conditions</h5>
Lines 250-261 Link Here
250
            <h4>List of rules</h4>
250
            <h4>List of rules</h4>
251
            [% FOR rule IN rules %]
251
            [% FOR rule IN rules %]
252
              <div class="rule">
252
              <div class="rule">
253
                <div class="duration">
253
                <div class="age">
254
                  <h5>Duration</h5>
254
                  <h5>Age</h5>
255
                  [% IF rule.duration.defined and rule.duration.length > 0 %]
255
                  [% IF rule.age.defined and rule.age.length > 0 %]
256
                    [% rule.duration %] days
256
                    [% rule.age %] days
257
                  [% ELSE %]
257
                  [% ELSE %]
258
                    There is no duration for this rule.
258
                    There is no age for this rule.
259
                  [% END %]
259
                  [% END %]
260
                </div>
260
                </div>
261
                <div class="blocks">
261
                <div class="blocks">
(-)a/t/db_dependent/Items/ToggleNewStatus.t (-16 / +16 lines)
Lines 67-73 my @rules = ( Link Here
67
                value => 'updated_value',
67
                value => 'updated_value',
68
             },
68
             },
69
        ],
69
        ],
70
        duration => '0',
70
        age => '0',
71
    },
71
    },
72
);
72
);
73
73
Lines 93-99 is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNew Link Here
93
                value => 'new_updated_value',
93
                value => 'new_updated_value',
94
             },
94
             },
95
        ],
95
        ],
96
        duration => '0',
96
        age => '0',
97
    },
97
    },
98
);
98
);
99
99
Lines 104-110 is( $modified_item->{new}, 'updated_value', q|ToggleNewStatus: The new value is Link Here
104
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
104
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
105
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new value is not updated| );
105
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new value is not updated| );
106
106
107
# Play with duration
107
# Play with age
108
$item = C4::Items::GetItem( $itemnumber );
108
$item = C4::Items::GetItem( $itemnumber );
109
my $dt_today = dt_from_string;
109
my $dt_today = dt_from_string;
110
my $days5ago = $dt_today->add_duration( DateTime::Duration->new( days => -5 ) );
110
my $days5ago = $dt_today->add_duration( DateTime::Duration->new( days => -5 ) );
Lines 126-155 $item = C4::Items::GetItem( $itemnumber ); Link Here
126
                value => 'new_updated_value',
126
                value => 'new_updated_value',
127
             },
127
             },
128
        ],
128
        ],
129
        duration => '10',
129
        age => '10',
130
    },
130
    },
131
);
131
);
132
C4::Items::ToggleNewStatus( { rules => \@rules } );
132
C4::Items::ToggleNewStatus( { rules => \@rules } );
133
$modified_item = C4::Items::GetItem( $itemnumber );
133
$modified_item = C4::Items::GetItem( $itemnumber );
134
is( $modified_item->{new}, 'updated_value', q|ToggleNewStatus: Duration = 10 : The new value is not updated|);
134
is( $modified_item->{new}, 'updated_value', q|ToggleNewStatus: Age = 10 : The new value is not updated|);
135
135
136
$rules[0]->{duration} = 5;
136
$rules[0]->{age} = 5;
137
$rules[0]->{substitutions}[0]{value} = 'new_updated_value5';
137
$rules[0]->{substitutions}[0]{value} = 'new_updated_value5';
138
C4::Items::ToggleNewStatus( { rules => \@rules } );
138
C4::Items::ToggleNewStatus( { rules => \@rules } );
139
$modified_item = C4::Items::GetItem( $itemnumber );
139
$modified_item = C4::Items::GetItem( $itemnumber );
140
is( $modified_item->{new}, 'new_updated_value5', q|ToggleNewStatus: Duration = 5 : The new value is updated|);
140
is( $modified_item->{new}, 'new_updated_value5', q|ToggleNewStatus: Age = 5 : The new value is updated|);
141
141
142
$rules[0]->{duration} = '';
142
$rules[0]->{age} = '';
143
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_empty_string';
143
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_empty_string';
144
C4::Items::ToggleNewStatus( { rules => \@rules } );
144
C4::Items::ToggleNewStatus( { rules => \@rules } );
145
$modified_item = C4::Items::GetItem( $itemnumber );
145
$modified_item = C4::Items::GetItem( $itemnumber );
146
is( $modified_item->{new}, 'new_updated_value_empty_string', q|ToggleNewStatus: Duration = '' : The new value is updated|);
146
is( $modified_item->{new}, 'new_updated_value_empty_string', q|ToggleNewStatus: Age = '' : The new value is updated|);
147
147
148
$rules[0]->{duration} = undef;
148
$rules[0]->{age} = undef;
149
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_undef';
149
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_undef';
150
C4::Items::ToggleNewStatus( { rules => \@rules } );
150
C4::Items::ToggleNewStatus( { rules => \@rules } );
151
$modified_item = C4::Items::GetItem( $itemnumber );
151
$modified_item = C4::Items::GetItem( $itemnumber );
152
is( $modified_item->{new}, 'new_updated_value_undef', q|ToggleNewStatus: Duration = undef : The new value is updated|);
152
is( $modified_item->{new}, 'new_updated_value_undef', q|ToggleNewStatus: Age = undef : The new value is updated|);
153
153
154
# Field deletion
154
# Field deletion
155
@rules = (
155
@rules = (
Lines 166-172 is( $modified_item->{new}, 'new_updated_value_undef', q|ToggleNewStatus: Duratio Link Here
166
                value => '',
166
                value => '',
167
             },
167
             },
168
        ],
168
        ],
169
        duration => '0',
169
        age => '0',
170
    },
170
    },
171
);
171
);
172
172
Lines 196-202 is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: Th Link Here
196
                value => 'new_value',
196
                value => 'new_value',
197
             },
197
             },
198
        ],
198
        ],
199
        duration => '0',
199
        age => '0',
200
    },
200
    },
201
);
201
);
202
202
Lines 223-229 is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: Link Here
223
                value => 'new_updated_value',
223
                value => 'new_updated_value',
224
             },
224
             },
225
        ],
225
        ],
226
        duration => '0',
226
        age => '0',
227
    },
227
    },
228
);
228
);
229
229
Lines 250-256 is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: Link Here
250
                value => 'new_updated_value',
250
                value => 'new_updated_value',
251
             },
251
             },
252
        ],
252
        ],
253
        duration => '0',
253
        age => '0',
254
    },
254
    },
255
);
255
);
256
256
Lines 273-279 is( $modified_item->{new}, 'new_updated_value', q|ToggleNewStatus: conditions mu Link Here
273
                value => 'another_new_updated_value',
273
                value => 'another_new_updated_value',
274
             },
274
             },
275
        ],
275
        ],
276
        duration => '0',
276
        age => '0',
277
    },
277
    },
278
);
278
);
279
279
(-)a/tools/toggle_new_status.pl (-2 / +1 lines)
Lines 82-88 if ( $op eq 'update' ) { Link Here
82
        }
82
        }
83
        push @{ $rule->{conditions} }, {}
83
        push @{ $rule->{conditions} }, {}
84
            unless @{ $rule->{conditions} };
84
            unless @{ $rule->{conditions} };
85
        $rule->{duration} = $cgi->param("duration_$unique_id");
85
        $rule->{age} = $cgi->param("age_$unique_id");
86
        push @rules, $rule;
86
        push @rules, $rule;
87
    }
87
    }
88
    my $syspref_content = to_json( \@rules );
88
    my $syspref_content = to_json( \@rules );
89
- 

Return to bug 11023