mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-26 04:21:36 +00:00
Fix updating of custom urls
This commit is contained in:
parent
a6944cb23c
commit
f695db4bb1
2 changed files with 22 additions and 19 deletions
|
@ -35,10 +35,13 @@ class CustomUrlsController < ApplicationController
|
||||||
url = CustomUrl.find(params[:id]) rescue nil
|
url = CustomUrl.find(params[:id]) rescue nil
|
||||||
|
|
||||||
if url
|
if url
|
||||||
if url.update_attributes(params[:custom_url])
|
url.article_id = params[:custom_url][:article_id]
|
||||||
|
url.name= params[:custom_url][:name]
|
||||||
|
if url.save
|
||||||
response[:status] = 200
|
response[:status] = 200
|
||||||
response[:message] = 'Successfully updated!'
|
response[:message] = 'Successfully updated!'
|
||||||
response[:obj] = url
|
resobj = {name: url.name, title: url.article.title}
|
||||||
|
response[:obj] = resobj
|
||||||
else
|
else
|
||||||
response[:status] = 400
|
response[:status] = 400
|
||||||
message = 'Update failed! Errors:'
|
message = 'Update failed! Errors:'
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
showEdit = function (url_id) {
|
showEdit = function (url_id) {
|
||||||
var parent = $('#' + url_id);
|
var parent = $('#' + url_id);
|
||||||
parent.find('> td').toggleClass('hidden');
|
parent.find('> td').toggleClass('hidden');
|
||||||
};
|
};
|
||||||
|
|
||||||
submitEdit = function (url_id) {
|
submitEdit = function (url_id) {
|
||||||
var parent = $('#' + url_id);
|
var parent = $('#' + url_id);
|
||||||
var form = parent.find('form');
|
var form = parent.find('form');
|
||||||
|
|
||||||
$.post('<%= custom_urls_path %>/' + url_id, form.serialize())
|
$.post('<%= custom_urls_path %>/' + url_id, form.serialize())
|
||||||
.done(function (data) {
|
.done(function (data) {
|
||||||
var nameField = parent.children('.name');
|
var nameField = parent.children('.name');
|
||||||
var articleField = parent.children('.article');
|
var articleField = parent.children('.article');
|
||||||
|
|
||||||
nameField.text(data.obj.name);
|
nameField.text(data.obj.name);
|
||||||
articleField.text(data.obj.title);
|
articleField.text(data.obj.title);
|
||||||
parent.find('> td').toggleClass('hidden');
|
parent.find('> td').toggleClass('hidden');
|
||||||
|
|
||||||
alert(data.message);
|
alert(data.message);
|
||||||
}).fail(function (errorRes) {
|
}).fail(function (errorRes) {
|
||||||
var error = JSON.parse(errorRes.responseText);
|
var error = JSON.parse(errorRes.responseText);
|
||||||
alert(error.message);
|
alert(error.message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteUrl = function (url_id) {
|
deleteUrl = function (url_id) {
|
||||||
var confirmed = confirm('Are you sure you want to delete this item?');
|
var confirmed = confirm('Are you sure you want to delete this item?');
|
||||||
|
|
||||||
if(confirmed) {
|
if (confirmed) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '<%= custom_urls_path %>/' + url_id,
|
url: '<%= custom_urls_path %>/' + url_id,
|
||||||
type: 'DELETE'
|
type: 'DELETE'
|
||||||
|
|
Loading…
Reference in a new issue