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'),
26 id: "menu-legacy-support-list-a",
28 redback: "{permissions: ['archiva-manage-configuration']}",
30 displayLegacyArtifactPathSupport()
36 //-------------------------
38 //-------------------------
40 LegacyArtifactPath = function(path, groupId, artifactId, version, classifier, type, update) {
41 //private String path;
42 this.path = ko.observable(path);
45 * The artifact reference, as " [groupId] :
46 * [artifactId] : [version] : [classifier] : [type] ".
48 //private String artifact;
49 //this.artifact=ko.observable(artifact);
51 //private String groupId;
52 this.groupId = ko.observable(groupId);
54 //private String artifactId;
55 this.artifactId = ko.observable(artifactId);
57 //private String version;
58 this.version = ko.observable(version);
60 //private String classifier;
61 this.classifier = ko.observable(classifier);
63 //private String type;
64 this.type = ko.observable(type);
66 this.modified = ko.observable();
68 this.artifact = ko.computed(function() {
69 var artifactValue = "";
71 artifactValue += this.groupId();
73 if (this.artifactId()) {
74 artifactValue += ":" + this.artifactId();
77 artifactValue += ":" + this.version();
79 if (this.classifier()) {
80 artifactValue += ":" + this.classifier();
83 artifactValue += ":" + this.type();
89 mapLegacyArtifactPaths = function(data) {
91 return $.isArray(data) ? $.map(data, function(item) {
92 return mapLegacyArtifactPath(item);
93 }) : [mapLegacyArtifactPath(data)];
98 mapLegacyArtifactPath = function(data) {
99 return data ? new LegacyArtifactPath(data.path, data.groupId, data.artifactId, data.version, data.classifier, data.type) : null;
102 activateLegacyArtifactPathFormValidation = function() {
103 var theForm = $("#main-content").find("#legacy-artifact-paths-edit-form");
104 var validator = theForm.validate({
105 showErrors: function(validator, errorMap, errorList) {
106 customShowError("#main-content #legacy-artifact-paths-edit-form", validator, errorMap, errorMap);
111 LegacyArtifactPathViewModel = function(legacyArtifactPath, update, legacyArtifactPathsViewModel) {
113 this.update = update;
114 this.legacyArtifactPath = legacyArtifactPath;
115 this.legacyArtifactPathsViewModel = legacyArtifactPathsViewModel;
117 this.display = function() {
118 var mainContent = $("#main-content");
119 ko.applyBindings(self, mainContent.find("#legacy-artifact-paths-edit").get(0));
120 mainContent.find("#legacy-artifact-paths-view-tabs-li-edit a").html($.i18n.prop("edit"));
121 activateLegacyArtifactPathFormValidation();
122 activateLegacyArtifactPathsEditTab();
125 displayGrid = function() {
126 activateLegacyArtifactPathsGridTab();
129 calculatePath = function() {
131 if (self.legacyArtifactPath.groupId()) {
132 path += self.legacyArtifactPath.groupId() + "/jars/";
134 if (self.legacyArtifactPath.artifactId()) {
135 path += self.legacyArtifactPath.artifactId();
137 if (self.legacyArtifactPath.version()) {
138 path += "-" + self.legacyArtifactPath.version();
140 if (self.legacyArtifactPath.classifier()) {
141 path += "-" + self.legacyArtifactPath.classifier();
143 if (self.legacyArtifactPath.type()) {
144 path += "." + self.legacyArtifactPath.type();
146 self.legacyArtifactPath.path(path);
149 this.save = function() {
150 var theForm = $("#main-content").find("#legacy-artifact-paths-edit-form");
151 if (!theForm.valid()) {
154 // do that on server side
155 /*if (theForm.find("#artifact" ).val()
156 !=theForm.find("#path" ).val()){
158 message: $.i18n.prop("path must match artifact"),
159 element: theForm.find("#path" ).get(0)
161 customShowError("#main-content #legacy-artifact-paths-edit-form", null, null, errorList);
164 // TODO call id exists if add ?
170 $.ajax("restServices/archivaServices/archivaAdministrationService/addLegacyArtifactPath",
173 contentType: 'application/json',
174 data: ko.toJSON(self.legacyArtifactPath),
176 success: function(data) {
177 self.legacyArtifactPath.modified(false);
178 self.legacyArtifactPathsViewModel.legacyArtifactPaths.push(self.legacyArtifactPath);
179 displaySuccessMessage($.i18n.prop('legacy-artifact-path.added', self.legacyArtifactPath.path()));
180 activateLegacyArtifactPathsGridTab();
182 error: function(data) {
183 var res = $.parseJSON(data.responseText);
184 displayRestError(res);
192 LegacyArtifactPathsViewModel = function() {
194 this.legacyArtifactPaths = ko.observableArray([]);
196 this.gridViewModel = new ko.simpleGrid.viewModel({
197 data: self.legacyArtifactPaths,
200 headerText: $.i18n.prop('legacy-artifact-paths.path'),
204 headerText: $.i18n.prop('legacy-artifact-paths.artifact'),
209 gridUpdateCallBack: function(networkProxy) {
210 $("#main-content").find("#legacy-artifact-paths-table").find("[title]").tooltip();
215 editLegacyArtifactPath = function(legacyArtifactPath) {
216 var legacyArtifactPathViewModel = new LegacyArtifactPathViewModel(legacyArtifactPath, true);
217 legacyArtifactPathViewModel.display();
220 removeLegacyArtifactPath = function(legacyArtifactPath) {
225 $.ajax("restServices/archivaServices/archivaAdministrationService/deleteLegacyArtifactPath?path=" + encodeURIComponent(legacyArtifactPath.path()),
229 success: function(data) {
230 self.legacyArtifactPaths.remove(legacyArtifactPath);
231 displaySuccessMessage($.i18n.prop('legacy-artifact-path.removed', legacyArtifactPath.path()));
232 activateLegacyArtifactPathsGridTab();
234 error: function(data) {
235 var res = $.parseJSON(data.responseText);
236 displayRestError(res);
238 complete: function() {
239 closeDialogConfirm();
243 }, $.i18n.prop('ok'), $.i18n.prop('cancel'), $.i18n.prop('legacy-artifact-path.delete.confirm', legacyArtifactPath.path()),
244 $("#legacy-artifact-path-delete-warning-tmpl").tmpl(legacyArtifactPath));
248 updateLegacyArtifactPath = function(legacyArtifactPath) {
254 displayLegacyArtifactPathSupport = function() {
256 var mainContent = $("#main-content");
257 mainContent.html(mediumSpinnerImg());
259 $.ajax("restServices/archivaServices/archivaAdministrationService/getLegacyArtifactPaths", {
262 success: function(data) {
263 mainContent.html($("#legacy-artifact-path-main").tmpl());
264 var legacyArtifactPathsViewModel = new LegacyArtifactPathsViewModel();
265 var legacyPaths = mapLegacyArtifactPaths(data);
266 $.log("legacyPaths:" + legacyPaths.length);
267 legacyArtifactPathsViewModel.legacyArtifactPaths(legacyPaths);
268 ko.applyBindings(legacyArtifactPathsViewModel, mainContent.find("#legacy-artifact-paths-view").get(0));
270 mainContent.find("#legacy-artifact-paths-view-tabs").on('show', function(e) {
271 if ($(e.target).attr("href") == "#legacy-artifact-paths-edit") {
272 var viewModel = new LegacyArtifactPathViewModel(new LegacyArtifactPath(), false, legacyArtifactPathsViewModel);
274 activateLegacyArtifactPathFormValidation();
277 if ($(e.target).attr("href") == "#legacy-artifact-paths-view") {
278 mainContent.find("#legacy-artifact-paths-view-tabs-li-edit a").html($.i18n.prop("add"));
285 activateLegacyArtifactPathsGridTab();
293 activateLegacyArtifactPathsGridTab = function() {
294 var mainContent = $("#main-content");
295 mainContent.find("#legacy-artifact-paths-view-tabs-li-edit").removeClass("active");
296 mainContent.find("#legacy-artifact-paths-edit").removeClass("active");
298 mainContent.find("#legacy-artifact-paths-view-tabs-li-grid").addClass("active");
299 mainContent.find("#legacy-artifact-paths-view").addClass("active");
300 mainContent.find("#legacy-artifact-paths-view-tabs-li-edit a").html($.i18n.prop("add"));
304 activateLegacyArtifactPathsEditTab = function() {
305 var mainContent = $("#main-content");
306 mainContent.find("#legacy-artifact-paths-view-tabs-li-grid").removeClass("active");
307 mainContent.find("#legacy-artifact-paths-view").removeClass("active");
309 mainContent.find("#legacy-artifact-paths-view-tabs-li-edit").addClass("active");
310 mainContent.find("#legacy-artifact-paths-edit").addClass("active");