| 5074 |
amit.gupta |
1 |
// increase the default animation speed to exaggerate the effect
|
|
|
2 |
jQuery.fx.speeds._default = 1000;
|
|
|
3 |
$(function() {
|
|
|
4 |
|
|
|
5 |
jQuery("#type").change(function(){
|
|
|
6 |
if($(this).val()=='brand'){
|
|
|
7 |
jQuery("#brand").show();
|
|
|
8 |
jQuery("#category").hide();
|
|
|
9 |
}else {
|
|
|
10 |
jQuery("#category").show();
|
|
|
11 |
jQuery("#brand").hide();
|
|
|
12 |
}
|
|
|
13 |
});
|
|
|
14 |
|
|
|
15 |
$('.edit-link').live('click', function() {
|
|
|
16 |
//close all the opened synonyms
|
|
|
17 |
$('.edit-cancel:visible').trigger('click');
|
|
|
18 |
var trEle = $(this).closest('tr');
|
|
|
19 |
var key = trEle.find('td.key').html();
|
|
|
20 |
value = trEle.find('td.synonyms').html();
|
|
|
21 |
var type = $("#type").val();
|
|
|
22 |
trEle.find('td.synonyms').html('<textarea rows="2" columns="150" onfocus="this.value=this.value">' + value + '</textarea>');
|
|
|
23 |
trEle.find('a.edit-cancel').show();
|
|
|
24 |
$(this).removeClass("edit-link").addClass("save-link").html("save").click(function(){
|
|
|
25 |
newValue = trEle.find('td.synonyms').find('textarea').val().replace(/(\s+)?,(\s+)?/g,",");
|
|
|
26 |
if (newValue.indexOf("\"") != -1 || newValue.indexOf("'") != -1){
|
|
|
27 |
alert("Single quote or bouble quotes are not allowed");
|
|
|
28 |
trEle.find('td.synonyms textarea').focus();
|
|
|
29 |
return false;
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
if(value != newValue){
|
|
|
33 |
if(newValue==""){
|
|
|
34 |
var conf = confirm("Are you sure you want to empty the value");
|
|
|
35 |
if(!conf){
|
|
|
36 |
trEle.find('td.synonyms textarea').val(value);
|
|
|
37 |
trEle.find('td.synonyms textarea').focus();
|
|
|
38 |
return false;
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
jQuery.ajax({
|
|
|
42 |
url:"synonym/update",
|
|
|
43 |
data: {'key':key, 'value':newValue, 'type':type},
|
|
|
44 |
dataType:'json',
|
|
|
45 |
success:function(data){
|
|
|
46 |
if(data){
|
|
|
47 |
value=newValue;
|
|
|
48 |
trEle.find('a.edit-cancel').trigger('click');
|
|
|
49 |
} else {
|
|
|
50 |
alert("Some problem occurred while saving. Please try again");
|
|
|
51 |
trEle.find('td.synonyms textarea').focus();
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
});
|
|
|
55 |
}else {
|
|
|
56 |
alert("No change to save.");
|
|
|
57 |
trEle.find('td.synonyms textarea').focus();
|
|
|
58 |
}
|
|
|
59 |
});
|
|
|
60 |
return false;
|
|
|
61 |
});
|
|
|
62 |
$('.edit-cancel').click(function(){
|
|
|
63 |
var trEle = $(this).closest('tr');
|
|
|
64 |
trEle.find('td.synonyms').html(value);
|
|
|
65 |
$(this).hide();
|
|
|
66 |
trEle.find('a.save-link').removeClass("save-link").addClass("edit-link").html("edit").unbind();
|
|
|
67 |
return false;
|
|
|
68 |
});
|
|
|
69 |
});
|