... | ... |
@@ -123,7 +123,7 @@ |
123 | 123 |
} |
124 | 124 |
|
125 | 125 |
.labels-left { |
126 |
- width:60%; |
|
126 |
+ width:75%; |
|
127 | 127 |
float:left; |
128 | 128 |
} |
129 | 129 |
.labels-tag { |
... | ... |
@@ -134,7 +134,7 @@ |
134 | 134 |
border:1px solid #dddddd; |
135 | 135 |
} |
136 | 136 |
.labels-right { |
137 |
- width:40%; |
|
137 |
+ width:25%; |
|
138 | 138 |
float:left; |
139 | 139 |
text-align:right; |
140 | 140 |
} |
... | ... |
@@ -71,13 +71,55 @@ |
71 | 71 |
} |
72 | 72 |
} |
73 | 73 |
elsif ($op eq 'api-delete') { |
74 |
- my $row_id = param('id'); |
|
74 |
+ my $row_id = param('row-id'); |
|
75 | 75 |
|
76 | 76 |
app->dbi->model('label')->delete(where => {row_id => $row_id}); |
77 | 77 |
|
78 | 78 |
$self->render(json => {success => 1}); |
79 | 79 |
return; |
80 | 80 |
} |
81 |
+ elsif ($op eq 'api-update') { |
|
82 |
+ my $row_id = param('row-id'); |
|
83 |
+ my $id = param('id'); |
|
84 |
+ my $color = param('color'); |
|
85 |
+ |
|
86 |
+ my $vc = app->vc; |
|
87 |
+ my $validation = $vc->validation; |
|
88 |
+ |
|
89 |
+ if (!length $id) { |
|
90 |
+ $validation->add_failed(id => "Name can't be blank"); |
|
91 |
+ } |
|
92 |
+ elsif (length $id > 100) { |
|
93 |
+ $validation->add_failed(id => "Name is too long"); |
|
94 |
+ } |
|
95 |
+ else { |
|
96 |
+ my $label = app->dbi->model('label')->select( |
|
97 |
+ where => { |
|
98 |
+ project => $project_row_id, |
|
99 |
+ id => $id |
|
100 |
+ } |
|
101 |
+ )->one; |
|
102 |
+ |
|
103 |
+ if ($label && $id ne $label->{id}) { |
|
104 |
+ $validation->add_failed(id => "Name has already been taken"); |
|
105 |
+ } |
|
106 |
+ } |
|
107 |
+ |
|
108 |
+ if (!length $color) { |
|
109 |
+ $validation->add_failed(color => "Color can't be blank"); |
|
110 |
+ } |
|
111 |
+ |
|
112 |
+ if ($validation->is_valid) { |
|
113 |
+ app->dbi->model('label')->update({id => $id, color => $color}, where => {row_id => $row_id}); |
|
114 |
+ |
|
115 |
+ $self->render(json => {success => 1, id => $id, color => $color}); |
|
116 |
+ return; |
|
117 |
+ } |
|
118 |
+ else { |
|
119 |
+ $self->render(json => {success => 0, message => $validation->messages->[0]}); |
|
120 |
+ return; |
|
121 |
+ } |
|
122 |
+ } |
|
81 | 123 |
} |
82 | 124 |
|
83 | 125 |
my $labels = app->dbi->model('label')->select( |
... | ... |
@@ -114,13 +156,34 @@ |
114 | 156 |
|
115 | 157 |
$('.labels-delete').on('click', function () { |
116 | 158 |
var li = $(this).closest('li'); |
117 |
- var id = li.attr('row-id'); |
|
118 |
- $.post('<%= url_for %>', {id : id, op : 'api-delete'}, function (result) { |
|
159 |
+ var row_id = li.attr('row-id'); |
|
160 |
+ $.post('<%= url_for %>', {'row-id' : row_id, op : 'api-delete'}, function (result) { |
|
119 | 161 |
if (result.success) { |
120 | 162 |
li.fadeOut(); |
121 | 163 |
} |
122 | 164 |
}); |
123 | 165 |
}); |
166 |
+ |
|
167 |
+ $('.labels-edit-save-btn').on('click', function () { |
|
168 |
+ var li = $(this).closest('li'); |
|
169 |
+ var row_id = li.attr('row-id'); |
|
170 |
+ var id = li.find('[name=label-id]').val(); |
|
171 |
+ var color = li.find('[name=color]').val(); |
|
172 |
+ |
|
173 |
+ $.post('<%= url_for %>', {'row-id' : row_id, op : 'api-update', id : id, color : color}, function (result) { |
|
174 |
+ |
|
175 |
+ if (result.success) { |
|
176 |
+ li.find('.labels-label-id').text(result.id); |
|
177 |
+ li.find('.labels-tag').css('background', result.color); |
|
178 |
+ |
|
179 |
+ li.find('.labels-display-area').show(); |
|
180 |
+ li.find('.labels-edit-area').hide(); |
|
181 |
+ } |
|
182 |
+ else { |
|
183 |
+ li.find('.labels-error').text(result.message); |
|
184 |
+ } |
|
185 |
+ }); |
|
186 |
+ }); |
|
124 | 187 |
}); |
125 | 188 |
% end |
126 | 189 |
|
... | ... |
@@ -161,7 +224,7 @@ |
161 | 224 |
<div class="labels-left"> |
162 | 225 |
<div class="labels-tag" style="background:<%= $label->{color} %>;"> |
163 | 226 |
<i class="icon icon-tag"></i> |
164 |
- <%= $label->{id} %> |
|
227 |
+ <span class="labels-label-id"><%= $label->{id} %></span> |
|
165 | 228 |
</div> |
166 | 229 |
</div> |
167 | 230 |
<div class="labels-right"> |
... | ... |
@@ -182,6 +245,7 @@ |
182 | 245 |
<%= input_tag 'color' => $label->{color}, class => 'labels-edit-label-color' %> |
183 | 246 |
<div class ="labels-edit-label-color-palette" style="background:<%= $label->{color} %>;"></div> |
184 | 247 |
</div> |
248 |
+ <div class="labels-error" style="display:inline-block;color:red;"></div> |
|
185 | 249 |
</div> |
186 | 250 |
<div class="labels-right"> |
187 | 251 |
<div class="labels-edit-cancel-btn btn"> |