render :partial => 'profiles/copy_form'
end
- # POST /profiles/copy/<id>?name=<name of new profile>
+ # POST /profiles/copy/<id>?name=<name of new profile>[&overwrite=<name of overwritten profile>]
def copy
verify_post_request
verify_ajax_request
require_parameters 'id'
- source_key=profile_id_to_key(params[:id].to_i)
+ source_id = params[:id].to_i
+ source_profile = Internal.quality_profiles.profile(source_id)
+
+ source_key=profile_id_to_key(source_id)
target_name = params['name']
- call_backend do
- Internal.qprofile_service.copyToName(source_key, target_name)
- flash[:notice]= message('quality_profiles.profile_x_not_activated', :params => target_name)
- render :text => 'ok', :status => 200
+ overwrite = (params['overwrite'] == target_name)
+ target_profile = nil
+
+ unless overwrite
+ target_profile = Internal.quality_profiles.profile(target_name, source_profile.language())
+ end
+
+ if target_profile.nil? || overwrite
+ call_backend do
+ Internal.qprofile_service.copyToName(source_key, target_name)
+ if overwrite
+ flash[:notice] = message('quality_profiles.copy_x_overwritten', :params => target_name)
+ else
+ flash[:notice] = message('quality_profiles.profile_x_not_activated', :params => target_name)
+ end
+ render :text => 'ok', :status => 200
+ end
+ else
+ render :text => message('quality_profiles.copy_overwrite_x', :params => target_name), :status => 409
end
end
</div>
<div class="modal-body">
<div class="modal-error"/>
+ <div class="modal-warning"/>
<div class="modal-field">
<label for="name"><%= message 'quality_profiles.copy_new_name' -%> <em class="mandatory">*</em></label>
<input id="copy-name" name="name" type="text" size="50" maxlength="100" autofocus="autofocus"/>
</div>
</div>
<div class="modal-foot">
+ <input type="hidden" value="" name="overwrite" id="copy-overwrite"/>
<input type="submit" value="<%= h message('copy') -%>" id="copy-submit"/>
<a href="#" onclick="return closeModalWindow()" id="copy-cancel"><%= h message('cancel') -%></a>
</div>
</fieldset>
</form>
<script>
- $j("#copy-profile-form").modalForm();
+ $j("#copy-profile-form").modalForm({
+ error: function (xhr) {
+ if (xhr.status == 409) {
+ $j('#copy-profile-form .modal-error').hide();
+ var warningElt = $j('#copy-profile-form .modal-warning');
+ $j('#copy-overwrite').val($j('#copy-name').val());
+ $j('#copy-profile-form input[type=submit]').removeAttr('disabled');
+ warningElt.html(xhr.responseText);
+ warningElt.show();
+ } else {
+ $j('#copy-profile-form .modal-warning').hide();
+ var errorElt = $j('#copy-profile-form .modal-error');
+ $j('.loading-image').addClass("hidden");
+ $j('#copy-profile-form input[type=submit]').removeAttr('disabled');
+ errorElt.html(xhr.responseText);
+ errorElt.show();
+ }
+ }
+ });
</script>
quality_profiles.remove_projects_confirm_button=Remove All
quality_profiles.copy_x_title=Copy Profile {0}
quality_profiles.copy_new_name=New name
+quality_profiles.copy_overwrite_x=You are about to copy this quality profile into the existing "{0}" profile, which will fully overwrite it. Please confirm the name if you want to overwrite, or choose another name.
+quality_profiles.copy_x_overwritten=Profile '{0}' has been overwritten.
quality_profiles.restore_built_in_profiles=Restore Built-in Profiles
quality_profiles.restore_built_in_profiles_confirmation=Are you sure you want to restore '{0}' profile(s) for '{1}' ?
quality_profiles.including=including