2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
19 define("archiva/admin/repository/legacy/main", ["jquery", 'i18n','knockout'],
20 function(jquery,i18n,ko) {
22 showMenu = function(administrationMenuItems) {
23 administrationMenuItems.push(
25 text: $.i18n.prop('menu.legacy-artifact-support'),
27 id: "menu-legacy-support-list-a",
29 redback: "{permissions: ['archiva-manage-configuration']}",
31 displayLegacyArtifactPathSupport();
37 //-------------------------
39 //-------------------------
41 LegacyArtifactPath = function(path, groupId, artifactId, version, classifier, type, update) {
42 //private String path;
43 this.path = ko.observable(path);
46 * The artifact reference, as " [groupId] :
47 * [artifactId] : [version] : [classifier] : [type] ".
49 //private String artifact;
50 //this.artifact=ko.observable(artifact);
52 //private String groupId;
53 this.groupId = ko.observable(groupId);
55 //private String artifactId;
56 this.artifactId = ko.observable(artifactId);
58 //private String version;
59 this.version = ko.observable(version);
61 //private String classifier;
62 this.classifier = ko.observable(classifier);
64 //private String type;
65 this.type = ko.observable(type);
67 this.modified = ko.observable();
69 this.artifact = ko.computed(function() {
70 var artifactValue = "";
72 artifactValue += this.groupId();
74 if (this.artifactId()) {
75 artifactValue += ":" + this.artifactId();
78 artifactValue += ":" + this.version();
80 if (this.classifier()) {
81 artifactValue += ":" + this.classifier();
84 artifactValue += ":" + this.type();
90 mapLegacyArtifactPaths = function(data) {
92 return $.isArray(data) ? $.map(data, function(item) {
93 return mapLegacyArtifactPath(item);
94 }) : [mapLegacyArtifactPath(data)];
99 mapLegacyArtifactPath = function(data) {
100 return data ? new LegacyArtifactPath(data.path, data.groupId, data.artifactId, data.version, data.classifier, data.type) : null;
103 activateLegacyArtifactPathFormValidation = function() {
104 var theForm = $("#main-content").find("#legacy-artifact-paths-edit-form");
105 var validator = theForm.validate({
106 showErrors: function(validator, errorMap, errorList) {
107 customShowError("#main-content #legacy-artifact-paths-edit-form", validator, errorMap, errorMap);
112 LegacyArtifactPathViewModel = function(legacyArtifactPath, update, legacyArtifactPathsViewModel) {
114 this.update = update;
115 this.legacyArtifactPath = legacyArtifactPath;
116 this.legacyArtifactPathsViewModel = legacyArtifactPathsViewModel;
118 this.display = function() {
119 var mainContent = $("#main-content");
120 ko.applyBindings(self, mainContent.find("#legacy-artifact-paths-edit").get(0));
121 mainContent.find("#legacy-artifact-paths-view-tabs-li-edit a").html($.i18n.prop("edit"));
122 activateLegacyArtifactPathFormValidation();
123 activateLegacyArtifactPathsEditTab();
126 displayGrid = function() {
127 activateLegacyArtifactPathsGridTab();
130 calculatePath = function() {
132 if (self.legacyArtifactPath.groupId()) {
133 path += self.legacyArtifactPath.groupId() + "/jars/";
135 if (self.legacyArtifactPath.artifactId()) {
136 path += self.legacyArtifactPath.artifactId();
138 if (self.legacyArtifactPath.version()) {
139 path += "-" + self.legacyArtifactPath.version();
141 if (self.legacyArtifactPath.classifier()) {
142 path += "-" + self.legacyArtifactPath.classifier();
144 if (self.legacyArtifactPath.type()) {
145 path += "." + self.legacyArtifactPath.type();
147 self.legacyArtifactPath.path(path);
150 this.save = function() {
151 var theForm = $("#main-content").find("#legacy-artifact-paths-edit-form");
152 if (!theForm.valid()) {
155 // do that on server side
156 /*if (theForm.find("#artifact" ).val()
157 !=theForm.find("#path" ).val()){
159 message: $.i18n.prop("path must match artifact"),
160 element: theForm.find("#path" ).get(0)
162 customShowError("#main-content #legacy-artifact-paths-edit-form", null, null, errorList);
165 // TODO call id exists if add ?
171 $.ajax("restServices/archivaServices/archivaAdministrationService/addLegacyArtifactPath",
174 contentType: 'application/json',
175 data: ko.toJSON(self.legacyArtifactPath),
177 success: function(data) {
178 self.legacyArtifactPath.modified(false);
179 self.legacyArtifactPathsViewModel.legacyArtifactPaths.push(self.legacyArtifactPath);
180 displaySuccessMessage($.i18n.prop('legacy-artifact-path.added', self.legacyArtifactPath.path()));
181 activateLegacyArtifactPathsGridTab();
183 error: function(data) {
184 var res = $.parseJSON(data.responseText);
185 displayRestError(res);
193 LegacyArtifactPathsViewModel = function() {
195 this.legacyArtifactPaths = ko.observableArray([]);
197 this.gridViewModel = new ko.simpleGrid.viewModel({
198 data: self.legacyArtifactPaths,
201 headerText: $.i18n.prop('legacy-artifact-paths.path'),
205 headerText: $.i18n.prop('legacy-artifact-paths.artifact'),
210 gridUpdateCallBack: function(networkProxy) {
211 $("#main-content").find("#legacy-artifact-paths-table").find("[title]").tooltip();
216 editLegacyArtifactPath = function(legacyArtifactPath) {
217 var legacyArtifactPathViewModel = new LegacyArtifactPathViewModel(legacyArtifactPath, true);
218 legacyArtifactPathViewModel.display();
221 removeLegacyArtifactPath = function(legacyArtifactPath) {
226 $.ajax("restServices/archivaServices/archivaAdministrationService/deleteLegacyArtifactPath?path=" + encodeURIComponent(legacyArtifactPath.path()),
230 success: function(data) {
231 self.legacyArtifactPaths.remove(legacyArtifactPath);
232 displaySuccessMessage($.i18n.prop('legacy-artifact-path.removed', legacyArtifactPath.path()));
233 activateLegacyArtifactPathsGridTab();
235 error: function(data) {
236 var res = $.parseJSON(data.responseText);
237 displayRestError(res);
239 complete: function() {
240 closeDialogConfirm();
244 }, $.i18n.prop('ok'), $.i18n.prop('cancel'), $.i18n.prop('legacy-artifact-path.delete.confirm', legacyArtifactPath.path()),
245 $("#legacy-artifact-path-delete-warning-tmpl").tmpl(legacyArtifactPath));
249 updateLegacyArtifactPath = function(legacyArtifactPath) {
255 displayLegacyArtifactPathSupport = function() {
257 var mainContent = $("#main-content");
258 mainContent.html(mediumSpinnerImg());
260 $.ajax("restServices/archivaServices/archivaAdministrationService/getLegacyArtifactPaths", {
263 success: function(data) {
264 mainContent.html($("#legacy-artifact-path-main").tmpl());
265 var legacyArtifactPathsViewModel = new LegacyArtifactPathsViewModel();
266 var legacyPaths = mapLegacyArtifactPaths(data);
267 $.log("legacyPaths:" + legacyPaths.length);
268 legacyArtifactPathsViewModel.legacyArtifactPaths(legacyPaths);
269 ko.applyBindings(legacyArtifactPathsViewModel, mainContent.find("#legacy-artifact-paths-view").get(0));
271 mainContent.find("#legacy-artifact-paths-view-tabs").on('show', function(e) {
272 if ($(e.target).attr("href") == "#legacy-artifact-paths-edit") {
273 var viewModel = new LegacyArtifactPathViewModel(new LegacyArtifactPath(), false, legacyArtifactPathsViewModel);
275 activateLegacyArtifactPathFormValidation();
278 if ($(e.target).attr("href") == "#legacy-artifact-paths-view") {
279 mainContent.find("#legacy-artifact-paths-view-tabs-li-edit a").html($.i18n.prop("add"));
286 activateLegacyArtifactPathsGridTab();
294 activateLegacyArtifactPathsGridTab = function() {
295 var mainContent = $("#main-content");
296 mainContent.find("#legacy-artifact-paths-view-tabs-li-edit").removeClass("active");
297 mainContent.find("#legacy-artifact-paths-edit").removeClass("active");
299 mainContent.find("#legacy-artifact-paths-view-tabs-li-grid").addClass("active");
300 mainContent.find("#legacy-artifact-paths-view").addClass("active");
301 mainContent.find("#legacy-artifact-paths-view-tabs-li-edit a").html($.i18n.prop("add"));
305 activateLegacyArtifactPathsEditTab = function() {
306 var mainContent = $("#main-content");
307 mainContent.find("#legacy-artifact-paths-view-tabs-li-grid").removeClass("active");
308 mainContent.find("#legacy-artifact-paths-view").removeClass("active");
310 mainContent.find("#legacy-artifact-paths-view-tabs-li-edit").addClass("active");
311 mainContent.find("#legacy-artifact-paths-edit").addClass("active");