diff options
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js/importlayer.js')
-rw-r--r-- | bitbake/lib/toaster/toastergui/static/js/importlayer.js | 94 |
1 files changed, 40 insertions, 54 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/importlayer.js b/bitbake/lib/toaster/toastergui/static/js/importlayer.js index 9d54286f4a..d14a8abcaf 100644 --- a/bitbake/lib/toaster/toastergui/static/js/importlayer.js +++ b/bitbake/lib/toaster/toastergui/static/js/importlayer.js | |||
@@ -148,7 +148,6 @@ function importLayerPageInit (ctx) { | |||
148 | headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, | 148 | headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, |
149 | success: function (data) { | 149 | success: function (data) { |
150 | if (data.error != "ok") { | 150 | if (data.error != "ok") { |
151 | show_error_message(data, layerData); | ||
152 | console.log(data.error); | 151 | console.log(data.error); |
153 | } else { | 152 | } else { |
154 | /* Success layer import now go to the project page */ | 153 | /* Success layer import now go to the project page */ |
@@ -164,59 +163,7 @@ function importLayerPageInit (ctx) { | |||
164 | } | 163 | } |
165 | }); | 164 | }); |
166 | 165 | ||
167 | function show_error_message(error, layerData) { | 166 | function enable_import_btn(enabled) { |
168 | |||
169 | var errorMsg = $("#import-error").fadeIn(); | ||
170 | var errorType = error.error; | ||
171 | var body = errorMsg.children("p"); | ||
172 | var title = errorMsg.children("h3"); | ||
173 | var optionsList = errorMsg.children("ul"); | ||
174 | var invalidLayerRevision = $("#invalid-layer-revision-hint"); | ||
175 | var layerRevisionCtrl = $("#layer-revision-ctrl"); | ||
176 | |||
177 | /* remove any existing items */ | ||
178 | optionsList.children().each(function(){ $(this).remove(); }); | ||
179 | body.text(""); | ||
180 | title.text(""); | ||
181 | invalidLayerRevision.hide(); | ||
182 | layerNameCtrl.removeClass("error"); | ||
183 | layerRevisionCtrl.removeClass("error"); | ||
184 | |||
185 | switch (errorType){ | ||
186 | case 'hint-layer-version-exists': | ||
187 | title.text("This layer already exists"); | ||
188 | body.html("A layer <strong>"+layerData.name+"</strong> already exists with this Git repository URL and this revision. You can:"); | ||
189 | optionsList.append("<li>Import <strong>"+layerData.name+"</strong> with a different revision </li>"); | ||
190 | optionsList.append("<li>or <a href=\""+ctx.layerDetailsUrl+error.existing_layer_version+"/\" >change the revision of the existing layer</a></li>"); | ||
191 | |||
192 | layerRevisionCtrl.addClass("error"); | ||
193 | |||
194 | invalidLayerRevision.html("A layer <strong>"+layerData.name+"</strong> already exists with this revision.<br />You can import <strong>"+layerData.name+"</strong> with a different revision"); | ||
195 | invalidLayerRevision.show(); | ||
196 | break; | ||
197 | |||
198 | case 'hint-layer-exists-with-different-url': | ||
199 | title.text("This layer already exists"); | ||
200 | body.html("A layer <strong>"+layerData.name+"</strong> already exists with a different Git repository URL:<p style='margin-top:10px;'><strong>"+error.current_url+"</strong></p><p>You can:</p>"); | ||
201 | optionsList.append("<li>Import the layer under a different name</li>"); | ||
202 | optionsList.append("<li>or <a href=\""+ctx.layerDetailsUrl+error.current_id+"/\" >change the Git repository URL of the existing layer</a></li>"); | ||
203 | duplicatedLayerName.html("A layer <strong>"+layerData.name+"</strong> already exists with a different Git repository URL.<br />To import this layer give it a different name."); | ||
204 | duplicatedLayerName.show(); | ||
205 | layerNameCtrl.addClass("error"); | ||
206 | break; | ||
207 | |||
208 | case 'hint-layer-exists': | ||
209 | title.text("This layer already exists"); | ||
210 | body.html("A layer <strong>"+layerData.name+"</strong> already exists. You can:"); | ||
211 | optionsList.append("<li>Import the layer under a different name</li>"); | ||
212 | break; | ||
213 | default: | ||
214 | title.text("Error") | ||
215 | body.text(data.error); | ||
216 | } | ||
217 | } | ||
218 | |||
219 | function enable_import_btn (enabled) { | ||
220 | var importAndAddHint = $("#import-and-add-hint"); | 167 | var importAndAddHint = $("#import-and-add-hint"); |
221 | 168 | ||
222 | if (enabled) { | 169 | if (enabled) { |
@@ -244,6 +191,38 @@ function importLayerPageInit (ctx) { | |||
244 | enable_import_btn(true); | 191 | enable_import_btn(true); |
245 | } | 192 | } |
246 | 193 | ||
194 | function layerExistsError(layer){ | ||
195 | var dupLayerInfo = $("#duplicate-layer-info"); | ||
196 | dupLayerInfo.find(".dup-layer-name").text(layer.name); | ||
197 | dupLayerInfo.find(".dup-layer-link").attr("href", layer.layerdetailurl); | ||
198 | dupLayerInfo.find("#dup-layer-vcs-url").text(layer.giturl); | ||
199 | dupLayerInfo.find("#dup-layer-revision").text(layer.revision); | ||
200 | |||
201 | $(".fields-apart-from-layer-name").fadeOut(function(){ | ||
202 | |||
203 | dupLayerInfo.fadeIn(); | ||
204 | }); | ||
205 | } | ||
206 | |||
207 | layerNameInput.on('blur', function() { | ||
208 | if (!$(this).val()){ | ||
209 | return; | ||
210 | } | ||
211 | var name = $(this).val(); | ||
212 | |||
213 | /* Check if the layer name exists */ | ||
214 | $.getJSON(ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: ctx.projectId, include_added: "true" , value: name }, function(layer) { | ||
215 | if (layer.list.length > 0) { | ||
216 | for (var i in layer.list){ | ||
217 | if (layer.list[i].name == name) { | ||
218 | console.log(layer.list[i]) | ||
219 | layerExistsError(layer.list[i]); | ||
220 | } | ||
221 | } | ||
222 | } | ||
223 | }); | ||
224 | }); | ||
225 | |||
247 | vcsURLInput.on('input', function() { | 226 | vcsURLInput.on('input', function() { |
248 | check_form(); | 227 | check_form(); |
249 | }); | 228 | }); |
@@ -260,6 +239,13 @@ function importLayerPageInit (ctx) { | |||
260 | return; | 239 | return; |
261 | } | 240 | } |
262 | 241 | ||
242 | if ($("#duplicate-layer-info").css("display") != "None"){ | ||
243 | $("#duplicate-layer-info").fadeOut(function(){ | ||
244 | $(".fields-apart-from-layer-name").show(); | ||
245 | }); | ||
246 | |||
247 | } | ||
248 | |||
263 | /* Don't remove the error class if we're displaying the error for another | 249 | /* Don't remove the error class if we're displaying the error for another |
264 | * reason. | 250 | * reason. |
265 | */ | 251 | */ |