]> source.dussan.org Git - archiva.git/blob
bc6db19e1ec10b3c27054b9736ab0a9f3300ba12
[archiva.git] /
1 /*
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
9  *
10  *   http://www.apache.org/licenses/LICENSE-2.0
11  *
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
17  * under the License.
18  */
19 define("archiva/admin/repository/legacy/main", ["jquery", 'i18n','knockout'],
20         function(jquery,i18n,ko) {
21
22             showMenu = function(administrationMenuItems) {
23                 administrationMenuItems.push(
24                         {
25                             text: $.i18n.prop('menu.legacy-artifact-support'),
26                             order:600,
27                             id: "menu-legacy-support-list-a",
28                             href: "#legacy",
29                             redback: "{permissions: ['archiva-manage-configuration']}",
30                             func: function() {
31                                 displayLegacyArtifactPathSupport();
32                             }
33                         });
34             };
35
36
37             //-------------------------
38             // legacy path part
39             //-------------------------
40
41             LegacyArtifactPath = function(path, groupId, artifactId, version, classifier, type, update) {
42                 //private String path;
43                 this.path = ko.observable(path);
44
45                 /**
46                  * The artifact reference, as " [groupId] :
47                  * [artifactId] : [version] : [classifier] : [type] ".
48                  */
49                 //private String artifact;
50                 //this.artifact=ko.observable(artifact);
51                 this.update = update;
52                 //private String groupId;
53                 this.groupId = ko.observable(groupId);
54
55                 //private String artifactId;
56                 this.artifactId = ko.observable(artifactId);
57
58                 //private String version;
59                 this.version = ko.observable(version);
60
61                 //private String classifier;
62                 this.classifier = ko.observable(classifier);
63
64                 //private String type;
65                 this.type = ko.observable(type);
66
67                 this.modified = ko.observable();
68
69                 this.artifact = ko.computed(function() {
70                     var artifactValue = "";
71                     if (this.groupId()) {
72                         artifactValue += this.groupId();
73                     }
74                     if (this.artifactId()) {
75                         artifactValue += ":" + this.artifactId();
76                     }
77                     if (this.version()) {
78                         artifactValue += ":" + this.version();
79                     }
80                     if (this.classifier()) {
81                         artifactValue += ":" + this.classifier();
82                     }
83                     if (this.type()) {
84                         artifactValue += ":" + this.type();
85                     }
86                     return artifactValue;
87                 }, this);
88             };
89
90             mapLegacyArtifactPaths = function(data) {
91                 if (data) {
92                     return $.isArray(data) ? $.map(data, function(item) {
93                         return mapLegacyArtifactPath(item);
94                     }) : [mapLegacyArtifactPath(data)];
95                 }
96                 return [];
97             };
98
99             mapLegacyArtifactPath = function(data) {
100                 return data ? new LegacyArtifactPath(data.path, data.groupId, data.artifactId, data.version, data.classifier, data.type) : null;
101             };
102
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);
108                     }
109                 });
110             };
111
112             LegacyArtifactPathViewModel = function(legacyArtifactPath, update, legacyArtifactPathsViewModel) {
113                 var self = this;
114                 this.update = update;
115                 this.legacyArtifactPath = legacyArtifactPath;
116                 this.legacyArtifactPathsViewModel = legacyArtifactPathsViewModel;
117
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();
124                 };
125
126                 displayGrid = function() {
127                     activateLegacyArtifactPathsGridTab();
128                 };
129
130                 calculatePath = function() {
131                     var path = "";
132                     if (self.legacyArtifactPath.groupId()) {
133                         path += self.legacyArtifactPath.groupId() + "/jars/";
134                     }
135                     if (self.legacyArtifactPath.artifactId()) {
136                         path += self.legacyArtifactPath.artifactId();
137                     }
138                     if (self.legacyArtifactPath.version()) {
139                         path += "-" + self.legacyArtifactPath.version();
140                     }
141                     if (self.legacyArtifactPath.classifier()) {
142                         path += "-" + self.legacyArtifactPath.classifier();
143                     }
144                     if (self.legacyArtifactPath.type()) {
145                         path += "." + self.legacyArtifactPath.type();
146                     }
147                     self.legacyArtifactPath.path(path);
148                 };
149
150                 this.save = function() {
151                     var theForm = $("#main-content").find("#legacy-artifact-paths-edit-form");
152                     if (!theForm.valid()) {
153                         return;
154                     }
155                     // do that on server side
156                     /*if (theForm.find("#artifact" ).val()
157                      !=theForm.find("#path" ).val()){
158                      var errorList=[{
159                      message: $.i18n.prop("path must match artifact"),
160                      element: theForm.find("#path" ).get(0)
161                      }];
162                      customShowError("#main-content #legacy-artifact-paths-edit-form", null, null, errorList);
163                      return;
164                      }*/
165                     // TODO call id exists if add ?
166                     clearUserMessages();
167                     $.log("save ok");
168                     if (self.update) {
169                         $.log("update");
170                     } else {
171                         $.ajax("restServices/archivaServices/archivaAdministrationService/addLegacyArtifactPath",
172                                 {
173                                     type: "POST",
174                                     contentType: 'application/json',
175                                     data: ko.toJSON(self.legacyArtifactPath),
176                                     dataType: 'json',
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();
182                                     },
183                                     error: function(data) {
184                                         var res = $.parseJSON(data.responseText);
185                                         displayRestError(res);
186                                     }
187                                 }
188                         );
189                     }
190                 };
191             };
192
193             LegacyArtifactPathsViewModel = function() {
194                 var self = this;
195                 this.legacyArtifactPaths = ko.observableArray([]);
196
197                 this.gridViewModel = new ko.simpleGrid.viewModel({
198                     data: self.legacyArtifactPaths,
199                     columns: [
200                         {
201                             headerText: $.i18n.prop('legacy-artifact-paths.path'),
202                             rowText: "path"
203                         },
204                         {
205                             headerText: $.i18n.prop('legacy-artifact-paths.artifact'),
206                             rowText: "artifact"
207                         }
208                     ],
209                     pageSize: 5,
210                     gridUpdateCallBack: function(networkProxy) {
211                         $("#main-content").find("#legacy-artifact-paths-table").find("[title]").tooltip();
212                     }
213                 });
214
215
216                 editLegacyArtifactPath = function(legacyArtifactPath) {
217                     var legacyArtifactPathViewModel = new LegacyArtifactPathViewModel(legacyArtifactPath, true);
218                     legacyArtifactPathViewModel.display();
219                 };
220
221                 removeLegacyArtifactPath = function(legacyArtifactPath) {
222
223                     openDialogConfirm(
224                             function() {
225
226                                 $.ajax("restServices/archivaServices/archivaAdministrationService/deleteLegacyArtifactPath?path=" + encodeURIComponent(legacyArtifactPath.path()),
227                                         {
228                                             type: "GET",
229                                             dataType: 'json',
230                                             success: function(data) {
231                                                 self.legacyArtifactPaths.remove(legacyArtifactPath);
232                                                 displaySuccessMessage($.i18n.prop('legacy-artifact-path.removed', legacyArtifactPath.path()));
233                                                 activateLegacyArtifactPathsGridTab();
234                                             },
235                                             error: function(data) {
236                                                 var res = $.parseJSON(data.responseText);
237                                                 displayRestError(res);
238                                             },
239                                             complete: function() {
240                                                 closeDialogConfirm();
241                                             }
242                                         }
243                                 );
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));
246
247                 };
248
249                 updateLegacyArtifactPath = function(legacyArtifactPath) {
250
251                 };
252
253             };
254
255             displayLegacyArtifactPathSupport = function() {
256                 screenChange();
257                 var mainContent = $("#main-content");
258                 mainContent.html(mediumSpinnerImg());
259
260                 $.ajax("restServices/archivaServices/archivaAdministrationService/getLegacyArtifactPaths", {
261                     type: "GET",
262                     dataType: 'json',
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));
270
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);
274                                 viewModel.display();
275                                 activateLegacyArtifactPathFormValidation();
276                                 clearUserMessages();
277                             }
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"));
280                                 clearUserMessages();
281                             }
282
283                         });
284
285
286                         activateLegacyArtifactPathsGridTab();
287                     }
288                 });
289
290
291             };
292
293
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");
298
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"));
302
303             };
304
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");
309
310                 mainContent.find("#legacy-artifact-paths-view-tabs-li-edit").addClass("active");
311                 mainContent.find("#legacy-artifact-paths-edit").addClass("active");
312             };
313
314
315
316
317         }
318 );