]> source.dussan.org Git - archiva.git/blob
0e703723051171aa018c14b8fb85489f01909b5b
[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/maven2/repositories",["jquery","i18n","jquery.tmpl","bootstrap","jquery.validate","knockout","knockout.simpleGrid"],
20 function(jquery,i18n,jqueryTmpl,bootstrap,jqueryValidate,ko) {
21
22   // FIXME this must be dynamic if we do a plugin mechanism with dynamic repositories types
23   // FIXME i18n
24
25   ManagedRepositoryType=function(type,label){
26     this.type=type;
27     this.label=label;
28   }
29
30   window.managedRepositoryTypes = [
31             new ManagedRepositoryType("default","Maven 2.x Repository")
32             ];
33
34   ManagedRepository=function(id,name,layout,indexDirectory,location,snapshots,releases,blockRedeployments,cronExpression,
35                              scanned,retentionTime,retentionCount,deleteReleasedSnapshots,stageRepoNeeded,description,
36                              skipPackedIndexCreation,feedsUrl,url){
37
38     var self=this;
39
40     //private String id;
41     this.id=ko.observable(id);
42     this.id.subscribe(function(newValue){self.modified(true)});
43
44     //private String name;
45     this.name=ko.observable(name);
46     this.name.subscribe(function(newValue){self.modified(true)});
47
48     //private String layout = "default";
49     this.layout=ko.observable(layout);
50     this.layout.subscribe(function(newValue){self.modified(true)});
51
52     //private String indexDirectory;
53     this.indexDirectory=ko.observable(indexDirectory);
54     this.indexDirectory.subscribe(function(newValue){self.modified(true)});
55
56     //private String location;
57     this.location=ko.observable(location);
58     this.location.subscribe(function(newValue){self.modified(true)});
59
60     //private String cronExpression = "0 0 * * * ?";
61     this.cronExpression=ko.observable(cronExpression);
62     this.cronExpression.subscribe(function(newValue){self.modified(true)});
63
64     //private ManagedRepository stagingRepository;
65
66     //private int retentionTime = 100;
67     this.retentionTime=ko.observable(retentionTime);
68     this.retentionTime.subscribe(function(newValue){self.modified(true)});
69
70     //private int retentionCount = 2;
71     this.retentionCount=ko.observable(retentionCount);
72     this.retentionCount.subscribe(function(newValue){self.modified(true)});
73
74     //private boolean scanned = true;
75     this.scanned=ko.observable(scanned?scanned:true);
76     this.scanned.subscribe(function(newValue){self.modified(true)});
77
78     //private boolean deleteReleasedSnapshots;
79     this.deleteReleasedSnapshots=ko.observable(deleteReleasedSnapshots);
80     this.deleteReleasedSnapshots.subscribe(function(newValue){self.modified(true)});
81
82     //private boolean stageRepoNeeded;
83     this.stageRepoNeeded=ko.observable(stageRepoNeeded);
84     this.stageRepoNeeded.subscribe(function(newValue){self.modified(true)});
85
86     //private boolean snapshots = false;
87     this.snapshots=ko.observable(snapshots?snapshots:false);
88     this.snapshots.subscribe(function(newValue){self.modified(true)});
89
90     //private boolean releases = true;
91     this.releases=ko.observable(releases?releases:false);
92     this.releases.subscribe(function(newValue){self.modified(true)});
93
94     //private boolean blockRedeployments = false;
95     this.blockRedeployments=ko.observable(blockRedeployments?blockRedeployments:false);
96     this.blockRedeployments.subscribe(function(newValue){self.modified(true)});
97
98     //private String name;
99     this.description=ko.observable(description);
100     this.description.subscribe(function(newValue){self.modified(true)});
101
102     this.skipPackedIndexCreation=ko.observable(skipPackedIndexCreation?skipPackedIndexCreation:false);
103     this.skipPackedIndexCreation.subscribe(function(newValue){self.modified(true)});
104
105     this.feedsUrl=feedsUrl;
106
107     this.url=url;
108
109     this.getTypeLabel=function(){
110       for(var i=0;i<window.managedRepositoryTypes.length;i++){
111         if (window.managedRepositoryTypes[i].type==self.layout()){
112           return window.managedRepositoryTypes[i].label;
113         }
114       }
115       return "no label";
116     }
117
118     this.modified=ko.observable(false);
119   }
120
121   ArchivaRepositoryStatistics=function(scanEndTime,scanStartTime,totalArtifactCount,totalArtifactFileSize,totalFileCount,
122                                        totalGroupCount,totalProjectCount,newFileCount,duration,managedRepository,lastScanDate){
123     //private Date scanEndTime;
124     this.scanEndTime = ko.observable(scanEndTime);
125
126     //private Date scanStartTime;
127     this.scanStartTime = ko.observable(scanStartTime);
128
129     //private long totalArtifactCount;
130     this.totalArtifactCount = ko.observable(totalArtifactCount);
131
132     //private long totalArtifactFileSize;
133     this.totalArtifactFileSize = ko.observable(totalArtifactFileSize);
134
135     //private long totalFileCount;
136     this.totalFileCount = ko.observable(totalFileCount);
137
138     //private long totalGroupCount;
139     this.totalGroupCount = ko.observable(totalGroupCount);
140
141     //private long totalProjectCount;
142     this.totalProjectCount = ko.observable(totalProjectCount);
143
144     //private long newFileCount;
145     this.newFileCount = ko.observable(newFileCount);
146
147     this.duration = ko.observable(duration);
148
149     this.managedRepository = managedRepository;
150
151     this.lastScanDate=ko.observable(lastScanDate);
152   }
153
154   mapManagedRepositories=function(data,applicationUrl){
155     var mappedManagedRepositories = $.map(data, function(item) {
156       var managedRepository = mapManagedRepository(item);
157       managedRepository.feedsUrl=applicationUrl+"/feeds/"+managedRepository.id();
158       managedRepository.url=applicationUrl+"/repository/"+managedRepository.id()
159       return managedRepository;
160     });
161     return mappedManagedRepositories;
162   }
163   mapManagedRepository=function(data){
164     if (data==null){
165       return null;
166     }
167     return new ManagedRepository(data.id,data.name,data.layout,data.indexDirectory,data.location,data.snapshots
168                                  ,data.releases,
169                                  data.blockRedeployments,data.cronExpression,
170                                  data.scanned,data.retentionTime,data.retentionCount,data.deleteReleasedSnapshots,
171                                  data.stageRepoNeeded,data.description,data.skipPackedIndexCreation);
172   }
173
174   mapArchivaRepositoryStatistics=function(data){
175     if (data==null){
176       return null;
177     }
178     return new ArchivaRepositoryStatistics(data.scanEndTime,data.scanStartTime,data.totalArtifactCount,data.totalArtifactFileSize,
179                                            data.totalFileCount,data.totalGroupCount,data.totalProjectCount,data.newFileCount,
180                                            data.duration,data.managedRepository,data.lastScanDate)
181   }
182
183   ManagedRepositoryViewModel=function(managedRepository, update, managedRepositoriesViewModel){
184     this.managedRepository=managedRepository;
185     this.managedRepositoriesViewModel = managedRepositoriesViewModel;
186     this.update = update;
187
188     var self = this;
189
190     this.availableLayouts = window.managedRepositoryTypes;
191
192     showCronExpressionDoc=function(){
193       //$.log("showCronExpressionDoc") ;
194     }
195
196     this.save=function(){
197       $.log('managedrepo save');
198       var valid = $("#main-content").find("#managed-repository-edit-form").valid();
199       if (valid==false) {
200           return;
201       }
202       $.log("save:"+this.managedRepository.name());
203       clearUserMessages();
204       var userMessages=$("#user-messages");
205       userMessages.html(mediumSpinnerImg());
206       $("#managed-repository-save-button" ).button('loading');
207       if (this.update){
208         $.ajax("restServices/archivaServices/managedRepositoriesService/updateManagedRepository",
209           {
210             type: "POST",
211             data: ko.toJSON(this.managedRepository),
212             contentType: 'application/json',
213             dataType: 'json',
214             success: function(data) {
215               displaySuccessMessage($.i18n.prop('managedrepository.updated',self.managedRepository.id()));
216               activateManagedRepositoriesGridTab();
217               self.managedRepository.modified(false);
218             },
219             complete: function(){
220               $("#managed-repository-save-button" ).button('reset');
221               removeMediumSpinnerImg(userMessages);
222             }
223           }
224         );
225       } else {
226         var url="restServices/archivaServices/managedRepositoriesService/fileLocationExists";
227         url+="?fileLocation="+encodeURIComponent(self.managedRepository.location());
228         $.ajax(url,
229         {
230           type: "GET",
231           dataType: 'json',
232           success: function(data) {
233             if (data){
234               var completeCallbackFn = function(){window.modalConfirmDialog.modal('hide')};
235               openDialogConfirm(
236                   function(){addManagedRepository(self.managedRepository,completeCallbackFn)},
237                   $.i18n.prop('ok'), $.i18n.prop('cancel'),
238                   $.i18n.prop('managedrepository.add.title'),
239                   $("#managed-repository-location-warning-tmpl").tmpl(self.managedRepository));
240             }else{
241               addManagedRepository(self.managedRepository);
242             }
243           },
244           complete: function(){
245             $("#managed-repository-save-button" ).button('reset');
246             removeMediumSpinnerImg(userMessages);
247           }
248         });
249       }
250     }
251
252     addManagedRepository=function(managedRepository,completeCallbackFn){
253       var curManagedRepository=managedRepository;
254       var callbackFn = completeCallbackFn;
255       var dataJson=ko.toJSON(managedRepository);
256       $.log("managedRepository.release:"+managedRepository.releases()+",dataJson:"+dataJson);
257       $.ajax("restServices/archivaServices/managedRepositoriesService/addManagedRepository",
258         {
259           type: "POST",
260           contentType: 'application/json',
261           data: dataJson,
262           dataType: 'json',
263           success: function(data) {
264             if (managedRepository.stageRepoNeeded()){
265               $.log("stageRepoNeeded:"+managedRepository.stageRepoNeeded());
266               // reload all to see the new staged repo
267               loadManagedRepositories(function(data){
268                 self.managedRepositoriesViewModel.managedRepositories(mapManagedRepositories(data));
269               });
270             } else {
271               curManagedRepository.location(data.location);
272               self.managedRepositoriesViewModel.managedRepositories.push(curManagedRepository);
273             }
274
275             displaySuccessMessage($.i18n.prop('managedrepository.added',curManagedRepository.id()));
276             curManagedRepository.modified(false);
277             activateManagedRepositoriesGridTab();
278           },
279           error: function(data) {
280             var res = $.parseJSON(data.responseText);
281             displayRestError(res);
282           },
283           complete:function(data){
284             if(callbackFn){
285               callbackFn();
286             }
287           }
288         }
289       );
290     }
291
292     displayGrid=function(){
293       activateManagedRepositoriesGridTab();
294     }
295
296   }
297
298   activateManagedRepositoryFormValidation=function(){
299     var validator = $("#main-content" ).find("#managed-repository-edit-form").validate({
300       rules: {
301         retentionTime : {
302           digits: true,
303           min: 1
304         },
305         retentionCount : {
306           digits: true,
307           min: 1,
308           max: 100
309         },
310         cronExpression: {
311           required: true,
312           remote: {
313             url: "restServices/archivaServices/commonServices/validateCronExpression",
314             type: "get"
315           }
316         },
317         id: {
318           required: true,
319           remote: {
320             url: "restServices/archivaUiServices/dataValidatorService/managedRepositoryIdNotExists",
321             type: "get"
322           }
323         }
324       },
325       showErrors: function(validator, errorMap, errorList) {
326         customShowError("#main-content #managed-repository-edit-form",validator,errorMap,errorMap);
327       }
328     });
329     validator.settings.messages["cronExpression"]=$.i18n.prop("cronExpression.notvalid");
330     validator.settings.messages["id"]=$.i18n.prop("id.required.or.alreadyexists");
331   }
332
333   ManagedRepositoriesViewModel=function(){
334     this.managedRepositories=ko.observableArray([]);
335
336     this.gridViewModel = null;
337     var self = this;
338
339     editManagedRepository=function(managedRepository){
340       var mainContent = $("#main-content");
341       var viewModel = new ManagedRepositoryViewModel(managedRepository,true,self);
342       ko.applyBindings(viewModel,mainContent.find("#managed-repository-edit").get(0));
343       activateManagedRepositoryEditTab();
344       mainContent.find("#managed-repository-edit-li a").html($.i18n.prop('edit'));
345       activateManagedRepositoryFormValidation();
346       activatePopoverDoc();
347     }
348
349     this.editManagedRepositoryWithId=function(managedRepositoryId){
350       $.each(self.managedRepositories(), function(index, value) {
351         if(value.id()==managedRepositoryId){
352           editManagedRepository(value);
353         }
354       });
355     }
356
357     scanNow=function(managedRepository){
358       clearUserMessages();
359       openDialogConfirm(
360           function(){
361             $("#dialog-confirm-modal" ).find("#modal-login-footer").append(smallSpinnerImg());
362             var checked = $("#managed-repository-scan-now-all").get(0).checked;
363             var url = "restServices/archivaServices/repositoriesService/scanRepositoryNow?";
364             url += "repositoryId="+encodeURIComponent(managedRepository.id());
365             url += "&fullScan="+(checked==true?"true":"false");
366             $.ajax(url,
367               {
368                 type: "GET",
369                 beforeSend:function(){
370                   displayInfoMessage($.i18n.prop("managedrepository.scan.started",managedRepository.id()));
371                   closeDialogConfirm();
372                 },
373                 success: function(data) {
374                   displaySuccessMessage($.i18n.prop("managedrepository.scanned",managedRepository.name()));
375                 },
376                 error: function(data) {
377                   var res = $.parseJSON(data.responseText);
378                   displayRestError(res);
379                 },
380                 complete: function(){
381                   removeSmallSpinnerImg();
382                   closeDialogConfirm();
383                 }
384               }
385             );
386           },
387           $.i18n.prop("ok"),
388           $.i18n.prop("cancel"),
389           $.i18n.prop("managedrepository.scan.now"),
390           $("#managed-repository-scan-now-modal-tmpl").tmpl(managedRepository));
391
392     }
393
394     removeManagedRepository=function(managedRepository){
395       clearUserMessages();
396       openDialogConfirm(
397           function(){
398             var url = "restServices/archivaServices/managedRepositoriesService/deleteManagedRepository?";
399             url += "repositoryId="+encodeURIComponent(managedRepository.id());
400             var checked = $("#managedrepository-deletecontent").get(0).checked;
401             url += "&deleteContent="+(checked==true?"true":"false");
402             var dialogText=$("#dialog-confirm-modal-body-text" );
403             dialogText.html(mediumSpinnerImg());
404             $.ajax(url,
405               {
406                 type: "GET",
407                   success: function(data) {
408                     self.managedRepositories.remove(managedRepository);
409                     displaySuccessMessage($.i18n.prop("managedrepository.deleted",managedRepository.name()));
410
411                   },
412                   error: function(data) {
413                     var res = $.parseJSON(data.responseText);
414                     displayRestError(res);
415                   },
416                   complete: function(){
417                     removeMediumSpinnerImg(dialogText);
418                     closeDialogConfirm();
419                   }
420               }
421             );
422
423           },
424           $.i18n.prop("ok"),
425           $.i18n.prop("cancel"),
426           $.i18n.prop("managedrepository.delete.confirm",managedRepository.name()),
427           $("#managed-repository-delete-warning-tmpl").tmpl(managedRepository));
428     }
429
430     updateManagedRepository=function(managedRepository){
431       var managedRepositoryViewModel = new ManagedRepositoryViewModel(managedRepository,true,this);
432       managedRepositoryViewModel.save();
433     }
434
435     this.bulkSave=function(){
436       $.log("bulkSave");
437       return getModifiedManagedRepositories().length>0;
438     }
439
440     getModifiedManagedRepositories=function(){
441       var prx = $.grep(self.managedRepositories(),
442           function (managedRepository,i) {
443             return managedRepository.modified();
444           });
445       return prx;
446     }
447     updateModifiedManagedRepositories=function(){
448       var repos = getModifiedManagedRepositories();
449
450       openDialogConfirm(function(){
451                           for (i=0;i<repos.length;i++){
452                             updateManagedRepository(repos[i]);
453                           }
454                           closeDialogConfirm();
455                         },
456                         $.i18n.prop('ok'),
457                         $.i18n.prop('cancel'),
458                         $.i18n.prop('managed.repository.bulk.save.confirm.title'),
459                         $.i18n.prop('managed.repository.bulk.save.confirm',repos.length));
460     }
461
462     directoriesScan=function(managedRepository){
463       $.log("directoriesScan:"+managedRepository.id());
464       clearUserMessages();
465       var url = "restServices/archivaServices/repositoriesService/scanRepositoryDirectoriesNow/"+managedRepository.id();
466       $.ajax(url,
467         {
468           type: "GET",
469           dataType: 'json',
470           beforeSend:function(){
471             displayInfoMessage($.i18n.prop("managedrepository.scan.directories.started", managedRepository.id()));
472           },
473           success: function(data) {
474             $.log(" scanRepositoryDirectoriesNow finished ");
475             displaySuccessMessage( $.i18n.prop("managedrepository.scan.directories.finished", managedRepository.id()));
476           },
477           error: function(data) {
478             var res = $.parseJSON(data.responseText);
479             displayRestError(res);
480           },
481           complete: function(){
482             removeSmallSpinnerImg();
483           }
484
485         }
486       );
487     }
488
489     showStats=function(managedRepository){
490       if ($(calculatePopoverId(managedRepository)).html()){
491         // we ask stats all the time ? if no uncomment return
492         //return;
493         $("#managedrepository-stats-"+escapeDot(managedRepository.id())).append(smallSpinnerImg());
494       }
495       var curRepo=managedRepository;
496       var url = "restServices/archivaServices/managedRepositoriesService/getManagedRepositoryStatistics/"+managedRepository.id();
497       url+="/"+encodeURIComponent(usedLang());
498       $.ajax(url,
499         {
500           type: "GET",
501           dataType: 'json',
502           success: function(data) {
503             if (data==null){
504               return;
505             }
506             var archivaRepositoryStatistics=mapArchivaRepositoryStatistics(data);
507             archivaRepositoryStatistics.managedRepository=curRepo;
508             var mainContent = $("#main-content");
509             mainContent.find("#managedrepository-stats-"+escapeDot(curRepo.id())).append($("#managed-repository-stats-tmpl").tmpl(archivaRepositoryStatistics));
510             mainContent.find("#managedrepository-stats-img-"+escapeDot(curRepo.id())).attr("data-content",$(calculatePopoverId(curRepo)).html());
511             mainContent.find("#managedrepository-stats-img-"+escapeDot(curRepo.id())).popover(
512                 {
513                   placement: "left",
514                   html: true,
515                   trigger:'manual'
516                 }
517             );
518
519             mainContent.find("#managedrepository-stats-img-"+escapeDot(curRepo.id())).popover('show');
520             removeSmallSpinnerImg();
521           },
522           error: function(data) {
523             var res = $.parseJSON(data.responseText);
524             displayRestError(res);
525           },
526           complete: function(){
527            }
528         }
529       );
530     }
531
532     calculatePopoverId=function(managedRepository){
533       return "#main-content #managedrepository-stats-"+escapeDot(managedRepository.id()) + " #managedrepository-stats-"+escapeDot(managedRepository.id())+"-popover";
534     }
535
536     hideStats=function(managedRepository){
537       $("#body_content" ).find(".popover" ).hide();
538     }
539
540     showPomSnippet=function(managedRepository){
541       var mainContent = $("#main-content");
542       mainContent.find("#managed-repositories-pom-snippet").html(mediumSpinnerImg());
543       mainContent.find('#managed-repositories-pom-snippet').show();
544       var url = "restServices/archivaServices/managedRepositoriesService/getPomSnippet/"+encodeURIComponent(managedRepository.id());
545       $.ajax(url,
546         {
547           type: "GET",
548           dataType: 'text',
549           success: function(data) {
550             $("#managed-repositories-pom-snippet").html($("#pom-snippet-tmpl").tmpl(data));
551           },
552           error: function(data) {
553             var res = $.parseJSON(data.responseText);
554             displayRestError(res);
555           },
556           complete: function(){
557           }
558         }
559       );
560
561     }
562
563     mergeRepo=function(managedRepository){
564       var userMessages=$("#user-messages");
565       userMessages.html(mediumSpinnerImg());
566       // is there any artifacts to merge ?
567       var artifactsNumberUrl = "restServices/archivaServices/browseService/artifacts/"+encodeURIComponent(managedRepository.id());
568       $.ajax(artifactsNumberUrl,{
569             type: "GET",
570             dataType: 'json',
571             success: function(data){
572               var artifacts=mapArtifacts(data);
573               $.log("artifactsNumber for '" + managedRepository.id() + "': " + artifacts.length);
574
575               if (artifacts<1){
576                 displayWarningMessage($.i18n.prop("managedrepository.merge.noartifacts", managedRepository.id()));
577                 return;
578               }
579
580               $.log("merge repo open dialog");
581               var dialogMergeRepo=$("#dialog-modal-merge-repo");
582               if (window.modalMergeRepoDialog==null) {
583                 window.modalMergeRepoDialog = dialogMergeRepo.modal();
584
585               }
586
587               loadManagedRepositories(function(data){
588
589                 var managedRepositories = $.map(mapManagedRepositories(data), function(item) {
590                     return item.id()==managedRepository.id()?null:item;
591                 });
592                 $("#dialog-modal-merge-repo-body-text").html($("#merge-repo-dialog-content" )
593                                                                   .tmpl({sourceRepoId:managedRepository.id(),repositories:managedRepositories}));
594                 window.modalMergeRepoDialog.modal('show');
595               });
596
597             },
598             complete: function(){
599               removeMediumSpinnerImg(userMessages);
600             }
601         }
602       );
603
604     }
605
606
607   }
608
609
610   mergeRepositories=function(sourceRepository,targetRepository){
611     $.log("mergeRepositories:"+sourceRepository+":"+targetRepository);
612
613     var mergeRepoDialogBodyId="dialog-modal-merge-repo-body-text";
614     var mergeRepoDialogBody=$("#"+mergeRepoDialogBodyId);
615     mergeRepoDialogBody.html(mediumSpinnerImg());
616
617     // check conflicts
618     var url = "restServices/archivaServices/mergeRepositoriesService/mergeConflictedArtifacts/"+encodeURIComponent(sourceRepository);
619     url+="/"+encodeURIComponent(targetRepository);
620     $.ajax(url, {
621         type: "GET",
622         dataType: 'json',
623         success: function(data){
624           var artifacts=mapArtifacts(data);
625           if (artifacts && artifacts.length){
626             // we have conflicts ask to skip or not
627             $.log("conflicts:"+artifacts.length);
628             displayWarningMessage($.i18n.prop("managedrepository.merge.conflicts", artifacts.length),"dialog-modal-merge-repo-body-text");
629             $.tmpl($("#merge-repo-skip-conflicts").html(),
630                 { artifacts:artifacts, sourceRepository: sourceRepository, targetRepository:targetRepository })
631                 .appendTo( "#dialog-modal-merge-repo-body-text" );
632             $("#dialog-modal-merge-repo-header-title" ).html($.i18n.prop("managedrepository.merge.conflicts.header",sourceRepository,targetRepository));
633           } else {
634             doMerge(sourceRepository,targetRepository,false);
635           }
636         },
637         complete: function(){
638           $.log("complete removeMediumSpinnerImg");
639           removeMediumSpinnerImg("#dialog-modal-merge-repo-body-text");
640         }
641     });
642
643
644
645   }
646
647   doMerge=function(sourceRepository,targetRepository,skipConflicts){
648     $.log("doMerge:"+sourceRepository+" to " + targetRepository + ", skipConflicts: " + skipConflicts);
649     window.modalMergeRepoDialog.modal('hide');
650     var userMessages=$("#user-messages");
651     userMessages.html(mediumSpinnerImg());
652     var url = "restServices/archivaServices/mergeRepositoriesService/mergeRepositories/"+encodeURIComponent(sourceRepository);
653     url+="/"+encodeURIComponent(targetRepository);
654     url+="/"+skipConflicts;
655     $.ajax(url, {
656         type: "GET",
657         dataType: 'json',
658         success: function(data){
659           displaySuccessMessage($.i18n.prop("managedrepository.merge.success", sourceRepository,targetRepository));
660         },
661         complete: function(){
662           removeMediumSpinnerImg(userMessages);
663         }
664     });
665   }
666
667   activateManagedRepositoriesGridTab=function(){
668     var mainContent = $("#main-content");
669     mainContent.find("#managed-repository-edit-li").removeClass("active");
670     mainContent.find("#managed-repository-edit").removeClass("active");
671
672     mainContent.find("#managed-repositories-view-li").addClass("active");
673     mainContent.find("#managed-repositories-view").addClass("active");
674     mainContent.find("#managed-repository-edit-li a").html($.i18n.prop("add"));
675   }
676
677   activateManagedRepositoryEditTab=function(){
678     var mainContent = $("#main-content");
679     mainContent.find("#managed-repositories-view-li").removeClass("active");
680     mainContent.find("#managed-repositories-view").removeClass("active");
681
682     mainContent.find("#managed-repository-edit-li").addClass("active");
683     mainContent.find("#managed-repository-edit").addClass("active");
684   }
685
686
687   //---------------------------
688   // Remote repositories part
689   //---------------------------
690
691
692
693   RemoteRepository=function(id,name,layout,indexDirectory,url,userName,password,timeout,downloadRemoteIndex,remoteIndexUrl,
694                             remoteDownloadNetworkProxyId,cronExpression,remoteDownloadTimeout,downloadRemoteIndexOnStartup,
695                             description,extraParametersEntries,extraHeadersEntries,checkPath){
696
697     var self=this;
698
699     //private String id;
700     this.id=ko.observable(id);
701     this.id.subscribe(function(newValue){self.modified(true)});
702
703     //private String name;
704     this.name=ko.observable(name);
705     this.name.subscribe(function(newValue){self.modified(true)});
706
707     //private String layout = "default";
708     this.layout=ko.observable(layout);
709     this.layout.subscribe(function(newValue){self.modified(true)});
710
711     //private String indexDirectory;
712     this.indexDirectory=ko.observable(indexDirectory);
713     this.indexDirectory.subscribe(function(newValue){self.modified(true)});
714
715     //private String url;
716     this.url=ko.observable(url);
717     this.url.subscribe(function(newValue){self.modified(true)});
718
719     //private String userName;
720     this.userName=ko.observable(userName);
721     this.userName.subscribe(function(newValue){self.modified(true)});
722
723     //private String password;
724     this.password=ko.observable(password);
725     this.password.subscribe(function(newValue){self.modified(true)});
726
727     //private int timeout = 60;
728     this.timeout=ko.observable(timeout);
729     this.timeout.subscribe(function(newValue){self.modified(true)});
730
731     //private boolean downloadRemoteIndex = false;
732     this.downloadRemoteIndex=ko.observable(downloadRemoteIndex?false:downloadRemoteIndex);
733     this.downloadRemoteIndex.subscribe(function(newValue){self.modified(true)});
734
735     //private String remoteIndexUrl = ".index";
736     this.remoteIndexUrl=ko.observable(remoteIndexUrl);
737     this.remoteIndexUrl.subscribe(function(newValue){self.modified(true)});
738
739     //private String remoteDownloadNetworkProxyId;
740     this.remoteDownloadNetworkProxyId=ko.observable(remoteDownloadNetworkProxyId);
741     this.remoteDownloadNetworkProxyId.subscribe(function(newValue){self.modified(true)});
742
743     //private String cronExpression = "0 0 08 ? * SUN";
744     this.cronExpression=ko.observable(cronExpression);
745     this.cronExpression.subscribe(function(newValue){self.modified(true)});
746
747     //private int remoteDownloadTimeout = 300;
748     this.remoteDownloadTimeout=ko.observable(remoteDownloadTimeout);
749     this.remoteDownloadTimeout.subscribe(function(newValue){self.modified(true)});
750
751     //private boolean downloadRemoteIndexOnStartup = false;
752     this.downloadRemoteIndexOnStartup=ko.observable(downloadRemoteIndexOnStartup?false:downloadRemoteIndexOnStartup);
753     this.downloadRemoteIndexOnStartup.subscribe(function(newValue){self.modified(true)});
754
755     this.description=ko.observable(description);
756     this.description.subscribe(function(newValue){self.modified(true)});
757
758     this.getTypeLabel=function(){
759       for(var i=0;i<window.managedRepositoryTypes.length;i++){
760         if (window.managedRepositoryTypes[i].type==self.layout()){
761           return window.managedRepositoryTypes[i].label;
762         }
763       }
764       return "no label";
765     }
766
767     this.extraParametersEntries=ko.observableArray(extraParametersEntries==null?new Array():extraParametersEntries);
768     this.extraParametersEntries.subscribe(function(newValue){
769       self.modified(true);
770     });
771
772     this.extraHeadersEntries=ko.observableArray(extraHeadersEntries==null?new Array():extraHeadersEntries);
773     this.extraHeadersEntries.subscribe(function(newValue){
774       self.modified(true);
775     });
776
777     this.checkPath=ko.observable(checkPath);
778     this.checkPath.subscribe(function(newValue){self.modified(true)});
779
780     this.modified=ko.observable(false);
781   }
782
783   mapRemoteRepository=function(data){
784     if (data==null){
785       return null;
786     }
787
788     var extraParametersEntries = data.extraParametersEntries == null ? []: $.each(data.extraParametersEntries,function(item){
789       return new Entry(item.key, item.value);
790     });
791     if (!$.isArray(extraParametersEntries)){
792       extraParametersEntries=[];
793     }
794
795     var extraHeadersEntries = data.extraHeadersEntries == null ? []: $.each(data.extraHeadersEntries,function(item){
796       return new Entry(item.key, item.value);
797     });
798     if (!$.isArray(extraHeadersEntries)){
799       extraHeadersEntries=[];
800     }
801
802     return new RemoteRepository(data.id,data.name,data.layout,data.indexDirectory,data.url,data.userName,data.password,
803                                 data.timeout,data.downloadRemoteIndex,data.remoteIndexUrl,data.remoteDownloadNetworkProxyId,
804                                 data.cronExpression,data.remoteDownloadTimeout,data.downloadRemoteIndexOnStartup,data.description,
805                                 extraParametersEntries,extraHeadersEntries,data.checkPath);
806   }
807
808   mapRemoteRepositories=function(data){
809     var mappedRemoteRepositories = $.map(data, function(item) {
810       return mapRemoteRepository(item);
811     });
812     return mappedRemoteRepositories;
813   }
814
815   RemoteRepositoryViewModel=function(remoteRepository, update, remoteRepositoriesViewModel){
816     this.remoteRepository=remoteRepository;
817     this.remoteRepositoriesViewModel = remoteRepositoriesViewModel;
818     this.networkProxies=ko.observableArray([]);
819     this.update = update;
820
821     var self = this;
822
823     this.availableLayouts = window.managedRepositoryTypes;
824
825     this.save=function(){
826       var valid = $("#main-content" ).find("#remote-repository-edit-form").valid();
827       if (valid==false) {
828         return;
829       }
830       clearUserMessages();
831       var userMessages=$("#user-messages");
832       userMessages.html(mediumSpinnerImg());
833       $("#remote-repository-save-button" ).button('loading');
834       if (update){
835         $.ajax("restServices/archivaServices/remoteRepositoriesService/updateRemoteRepository",
836           {
837             type: "POST",
838             data: ko.toJSON(this.remoteRepository),
839             contentType: 'application/json',
840             dataType: 'json',
841             success: function(data) {
842               displaySuccessMessage($.i18n.prop('remoterepository.updated',self.remoteRepository.id()));
843               activateRemoteRepositoriesGridTab();
844               self.remoteRepository.modified(false);
845             },
846             error: function(data) {
847               var res = $.parseJSON(data.responseText);
848               displayRestError(res);
849             },
850             complete: function(){
851               $("#remote-repository-save-button" ).button('reset');
852               removeMediumSpinnerImg(userMessages);
853             }
854           }
855         );
856       }else {
857         $.ajax("restServices/archivaServices/remoteRepositoriesService/addRemoteRepository",
858           {
859             type: "POST",
860             data: ko.toJSON(this.remoteRepository),
861             contentType: 'application/json',
862             dataType: 'json',
863             success: function(data) {
864               self.remoteRepository.modified(false);
865               self.remoteRepositoriesViewModel.remoteRepositories.push(self.remoteRepository);
866               displaySuccessMessage($.i18n.prop('remoterepository.added'));
867               activateRemoteRepositoriesGridTab();
868               removeMediumSpinnerImg(userMessages);
869             },
870             error: function(data) {
871               var res = $.parseJSON(data.responseText);
872               displayRestError(res);
873             }
874           }
875         );
876       }
877     }
878
879     displayGrid=function(){
880       activateRemoteRepositoriesGridTab();
881     }
882
883     addExtraParameter=function(){
884
885       var mainContent=$("#main-content");
886       mainContent.find("#extra-parameters-error" ).empty();
887       var key=mainContent.find("#extraParameter-key").val();
888       if($.trim(key).length<1){
889         displayErrorMessage( $.i18n.prop("key.empty.error.message"),"extra-parameters-error");
890         return;
891       }
892       var value=mainContent.find("#extraParameter-value").val();
893       $.log("addExtraParameter="+key+":"+value);
894       var oldTab = self.remoteRepository.extraParametersEntries();
895       oldTab.push(new Entry(key,value));
896       self.remoteRepository.extraParametersEntries(oldTab);
897       mainContent.find("#extraParameter-key").val("");
898       mainContent.find("#extraParameter-value").val("");
899       self.remoteRepository.modified(true);
900     }
901
902     deleteExtraParameter=function(key){
903       for(var i=0;i<self.remoteRepository.extraParametersEntries().length;i++){
904         var entry=self.remoteRepository.extraParametersEntries()[i];
905         if (entry.key==key){
906           self.remoteRepository.extraParametersEntries.remove(entry);
907           self.remoteRepository.modified(true);
908         }
909       }
910     }
911
912     addExtraHeader=function(){
913
914       var mainContent=$("#main-content");
915       mainContent.find("#extra-headers-error" ).empty();
916       var key=mainContent.find("#extraHeader-key").val();
917       if( $.trim(key).length<1){
918         if($.trim(key).length<1){
919           displayErrorMessage( $.i18n.prop("key.empty.error.message"),"extra-headers-error");
920           return;
921         }
922       }
923       var value=mainContent.find("#extraHeader-value").val();
924       $.log("addExtraParameter="+key+":"+value);
925       var oldTab = self.remoteRepository.extraHeadersEntries();
926       oldTab.push(new Entry(key,value));
927       self.remoteRepository.extraHeadersEntries(oldTab);
928       mainContent.find("#extraHeader-key").val("");
929       mainContent.find("#extraHeader-value").val("");
930       self.remoteRepository.modified(true);
931     }
932
933     deleteExtraHeader=function(key){
934       for(var i=0;i<self.remoteRepository.extraHeadersEntries().length;i++){
935         var entry=self.remoteRepository.extraHeadersEntries()[i];
936         if (entry.key==key){
937           self.remoteRepository.extraHeadersEntries.remove(entry);
938           self.remoteRepository.modified(true);
939         }
940       }
941     }
942
943   }
944
945   RemoteRepositoriesViewModel=function(){
946     this.remoteRepositories=ko.observableArray([]);
947     this.applicationUrl=null;
948     this.gridViewModel = null;
949     var self = this;
950
951     editRemoteRepository=function(remoteRepository){
952       $.log("editRemoteRepository");
953       $.ajax("restServices/archivaServices/networkProxyService/getNetworkProxies", {
954           type: "GET",
955           dataType: 'json',
956           success: function(data) {
957             var viewModel = new RemoteRepositoryViewModel(remoteRepository,true,self);
958             viewModel.networkProxies(mapNetworkProxies(data));
959             var mainContent = $("#main-content");
960
961             ko.applyBindings(viewModel,mainContent.find("#remote-repository-edit").get(0));
962             activateRemoteRepositoryEditTab();
963             mainContent.find("#remote-repository-edit-li a").html($.i18n.prop('edit'));
964             activateRemoteRepositoryFormValidation(false);
965             activatePopoverDoc();
966           }
967       })
968
969     }
970
971     removeRemoteRepository=function(remoteRepository){
972       clearUserMessages();
973       openDialogConfirm(
974           function(){
975             var dialogText=$("#dialog-confirm-modal-body-text" );
976             dialogText.html(mediumSpinnerImg());
977             $.ajax("restServices/archivaServices/remoteRepositoriesService/deleteRemoteRepository/"+encodeURIComponent(remoteRepository.id()),
978                   {
979                     type: "GET",
980                     success: function(data) {
981                       self.remoteRepositories.remove(remoteRepository);
982                       displaySuccessMessage($.i18n.prop('remoterepository.deleted',remoteRepository.id()));
983                     },
984                     error: function(data) {
985                       var res = $.parseJSON(data.responseText);
986                       displayRestError(res);
987                     },
988                     complete:function(){
989                       removeMediumSpinnerImg(dialogText);
990                       closeDialogConfirm();
991                     }
992                   }
993                 )}, $.i18n.prop('ok'),
994                 $.i18n.prop('cancel'),
995                 $.i18n.prop('remoterepository.delete.confirm',remoteRepository.id()),
996                 $("#remote-repository-delete-modal-tmpl").tmpl(remoteRepository));
997
998     }
999
1000     this.bulkSave=function(){
1001       return getModifiedRemoteRepositories().length>0;
1002     }
1003
1004     getModifiedRemoteRepositories=function(){
1005       var prx = $.grep(self.remoteRepositories(),
1006           function (remoteRepository,i) {
1007             return remoteRepository.modified();
1008           });
1009       return prx;
1010     }
1011
1012     updateModifiedRemoteRepositories=function(){
1013       var modifiedRemoteRepositories = getModifiedRemoteRepositories();
1014
1015       openDialogConfirm(function(){
1016                           for(var i=0;i<modifiedRemoteRepositories.length;i++){
1017                             updateRemoteRepository(modifiedRemoteRepositories[i]);
1018                           }
1019                           closeDialogConfirm();
1020                         },
1021                         $.i18n.prop('ok'),
1022                         $.i18n.prop('cancel'),
1023                         $.i18n.prop('remoterepositories.bulk.save.confirm.title'),
1024                         $.i18n.prop('remoterepositories.bulk.save.confirm',modifiedRemoteRepositories.length));
1025     }
1026
1027     updateRemoteRepository=function(remoteRepository){
1028       var viewModel = new RemoteRepositoryViewModel(remoteRepository,true,self);
1029       viewModel.save();
1030     }
1031
1032     scheduleDownloadRemoteIndex=function(remoteRepository){
1033       openDialogConfirm(
1034         function(){
1035
1036           var url = "restServices/archivaServices/repositoriesService/scheduleDownloadRemoteIndex?";
1037           url += "repositoryId="+encodeURIComponent(remoteRepository.id());
1038
1039           var now = $("#remoterepository-scan-now").get(0).checked;
1040
1041           var full = $("#remoterepository-scan-full").get(0).checked;
1042
1043           url += "&now="+(now==true?"true":"false");
1044           url += "&fullDownload="+(full==true?"true":"false");
1045           $.ajax(url,
1046             {
1047               type: "GET",
1048                 success: function(data) {
1049                   clearUserMessages();
1050                   displaySuccessMessage($.i18n.prop("remoterepository.download.remote.scheduled",remoteRepository.name()));
1051                 },
1052                 error: function(data) {
1053                   var res = $.parseJSON(data.responseText);
1054                   displayRestError(res);
1055                 },
1056                 complete: function(){
1057                   closeDialogConfirm();
1058                 }
1059             }
1060           );
1061
1062         },
1063         $.i18n.prop("ok"),
1064         $.i18n.prop("cancel"),
1065         $.i18n.prop("remoterepository.download.remote.confirm",remoteRepository.name()),
1066         $("#remote-repository-scan-modal-tmpl").tmpl(remoteRepository));
1067     }
1068   }
1069
1070   /**
1071    *
1072    * @param validateId to validate if id already exists: not needed for update !
1073    */
1074   activateRemoteRepositoryFormValidation=function(validateId){
1075     // FIXME find a way to activate cronExpression validation only if downloadRemote is activated !
1076     var validator = null;
1077     if (validateId){
1078       validator = $("#main-content" ).find("#remote-repository-edit-form").validate({
1079         rules: {
1080           id: {
1081             required: true,
1082             remote: {
1083               url: "restServices/archivaUiServices/dataValidatorService/remoteRepositoryIdNotExists",
1084               type: "get"
1085             }
1086           }
1087         },
1088         showErrors: function(validator, errorMap, errorList) {
1089           customShowError("#main-content #remote-repository-edit-form",validator,errorMap,errorMap);
1090         }
1091       });
1092     } else {
1093       validator = $("#main-content" ).find("#remote-repository-edit-form").validate({
1094         rules: {
1095           id: {
1096             required: true
1097           }
1098         },
1099         showErrors: function(validator, errorMap, errorList) {
1100           customShowError("#main-content #remote-repository-edit-form",validator,errorMap,errorMap);
1101         }
1102       });
1103     }
1104     validator.settings.messages["cronExpression"]=$.i18n.prop("cronExpression.notvalid");
1105     validator.settings.messages["id"]=$.i18n.prop("id.required.or.alreadyexists");
1106   }
1107
1108   activateRemoteRepositoriesGridTab=function(){
1109     var mainContent = $("#main-content");
1110     mainContent.find("#remote-repository-edit-li").removeClass("active");
1111     mainContent.find("#remote-repository-edit").removeClass("active");
1112
1113     mainContent.find("#remote-repositories-view-li").addClass("active");
1114     mainContent.find("#remote-repositories-view").addClass("active");
1115     mainContent.find("#remote-repository-edit-li a").html($.i18n.prop("add"));
1116   }
1117
1118   activateRemoteRepositoryEditTab=function(){
1119     var mainContent = $("#main-content");
1120     mainContent.find("#remote-repositories-view-li").removeClass("active");
1121     mainContent.find("#remote-repositories-view").removeClass("active");
1122
1123     mainContent.find("#remote-repository-edit-li").addClass("active");
1124     mainContent.find("#remote-repository-edit").addClass("active");
1125   }
1126
1127   //---------------------------
1128   // Screen loading
1129   //---------------------------
1130
1131    /**
1132     *
1133     * @param successFnManagedRepositories function called with param managedRepositoriesViewModel when managed repositories grid has been displayed
1134     * @param successFnRemoteRepositories  function called with param remoteRepositoriesViewModel when remote repositories grid has been displayed
1135     */
1136   displayRepositoriesGrid=function(successFnManagedRepositories,successFnRemoteRepositories){
1137     screenChange();
1138     var mainContent = $("#main-content");
1139     mainContent.html(mediumSpinnerImg());
1140     mainContent.html($("#repositoriesMain").tmpl());
1141     mainContent.find("#repositories-tabs a:first").tab("show");
1142
1143     mainContent.find("#managed-repositories-content").append(mediumSpinnerImg());
1144     mainContent.find("#remote-repositories-content").append(mediumSpinnerImg());
1145
1146     var managedRepositoriesViewModel = new ManagedRepositoriesViewModel();
1147     var remoteRepositoriesViewModel = new RemoteRepositoriesViewModel();
1148
1149     $.ajax({
1150         url: "restServices/archivaServices/archivaAdministrationService/applicationUrl",
1151         type: "GET",
1152         dataType: 'text',
1153         success: function(applicationUrl){
1154           $.log("applicationUrl:"+applicationUrl);
1155           loadManagedRepositories(function(data) {
1156
1157
1158             managedRepositoriesViewModel.managedRepositories(
1159                 mapManagedRepositories(data,applicationUrl?applicationUrl:window.location.toString().substringBeforeLast("/")));
1160
1161             managedRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({
1162               data: managedRepositoriesViewModel.managedRepositories,
1163               columns: [
1164                 {
1165                   headerText: $.i18n.prop('identifier'),
1166                   rowText: "id"
1167                 },
1168                 {
1169                   headerText: $.i18n.prop('name'),
1170                   rowText: "name"
1171                 },
1172                 {
1173                 headerText: $.i18n.prop('type'),
1174                 rowText: "getTypeLabel",
1175                 // FIXME i18n
1176                 title: "Repository type (default is Maven 2)"
1177                 }
1178               ],
1179               pageSize: 5,
1180               gridUpdateCallBack: function(){
1181                 // a bit ugly
1182                 //$("#main-content" ).find("#managed-repositories-table").find("[title]").tooltip({animation:"false"});
1183               }
1184             });
1185             var mainContent = $("#main-content");
1186             ko.applyBindings(managedRepositoriesViewModel,mainContent.find("#managed-repositories-view").get(0));
1187             activatePopoverDoc();
1188             mainContent.find("#managed-repositories-pills #managed-repositories-view-a").tab('show');
1189             removeMediumSpinnerImg(mainContent.find("#managed-repositories-content"));
1190             activateManagedRepositoriesGridTab();
1191             if(successFnManagedRepositories){
1192               successFnManagedRepositories(managedRepositoriesViewModel);
1193             }
1194           });
1195
1196           loadRemoteRepositories(function(data) {
1197             remoteRepositoriesViewModel.remoteRepositories(mapRemoteRepositories(data));
1198             remoteRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({
1199               data: remoteRepositoriesViewModel.remoteRepositories,
1200               columns: [
1201                 {
1202                   headerText: $.i18n.prop('identifier'),
1203                   rowText: "id"
1204                 },
1205                 {
1206                   headerText: $.i18n.prop('name'),
1207                   rowText: "name"
1208                 },
1209                 {
1210                   headerText: $.i18n.prop('url'),
1211                   rowText: "url"
1212                 },
1213                 {
1214                 headerText: $.i18n.prop('type'),
1215                 rowText: "getTypeLabel",
1216                 // FIXME i18n
1217                 title: "Repository type (default is Maven 2)"
1218                 }
1219               ],
1220               pageSize: 5,
1221               gridUpdateCallBack: function(){
1222                 $.log("remote repositories gridUpdateCallBack");
1223
1224
1225                 mainContent.find(".remote-check").each(function( index ) {
1226                   var repoId = $( this ).attr("id");
1227                   console.log( index + ": " + repoId);
1228                   $.ajax({
1229                     url: "restServices/archivaServices/remoteRepositoriesService/checkRemoteConnectivity/"+repoId.substringAfterFirst("remote-check-"),
1230                     type: "GET",
1231                     dataType: 'text',
1232                     success: function(result){
1233                       $.log("result:"+result);
1234                       if(result=="true"){
1235                         mainContent.find("img[id='"+repoId+"']").attr("src", "images/weather-clear.png" );
1236                       } else {
1237                         mainContent.find("img[id='"+repoId+"']").attr("src", "images/weather-severe-alert-16-16.png" );
1238                       }
1239                     },
1240                     error: function(result){
1241                         mainContent.find("img[id='"+repoId+"']").attr("src", "images/weather-severe-alert-16-16.png" );
1242                     }
1243                   });
1244                 });
1245
1246
1247               }
1248             });
1249             var mainContent = $("#main-content");
1250             ko.applyBindings(remoteRepositoriesViewModel,mainContent.find("#remote-repositories-view").get(0));
1251             mainContent.find("#remote-repositories-pills #remote-repositories-view-a").tab('show');
1252             removeMediumSpinnerImg(mainContent.find("#remote-repositories-content"));
1253             activatePopoverDoc();
1254             if(successFnRemoteRepositories){
1255               successFnRemoteRepositories(managedRepositoriesViewModel);
1256             }
1257           });
1258         }
1259     }
1260     );
1261
1262
1263     mainContent.find("#managed-repositories-pills").on('show', function (e) {
1264       var mainContent = $("#main-content");
1265       if ($(e.target).attr("href")=="#managed-repository-edit") {
1266         var managedRepo=new ManagedRepository();
1267         managedRepo.cronExpression("0 0 * * * ?");
1268         var viewModel = new ManagedRepositoryViewModel(managedRepo,false,managedRepositoriesViewModel);
1269         ko.applyBindings(viewModel,mainContent.find("#managed-repository-edit").get(0));
1270         activateManagedRepositoryFormValidation();
1271         activatePopoverDoc();
1272       }
1273       if ($(e.target).attr("href")=="#managed-repositories-view") {
1274         mainContent.find("#managed-repository-edit-li a").html($.i18n.prop("add"));
1275       }
1276
1277     });
1278
1279     mainContent.find("#remote-repositories-pills").on('show', function (e) {
1280       if ($(e.target).attr("href")=="#remote-repository-edit") {
1281         $.ajax("restServices/archivaServices/networkProxyService/getNetworkProxies", {
1282             type: "GET",
1283             dataType: 'json',
1284             success: function(data) {
1285               var remoteRepo=new RemoteRepository();
1286               remoteRepo.cronExpression("0 0 08 ? * SUN");
1287               var viewModel = new RemoteRepositoryViewModel(remoteRepo,false,remoteRepositoriesViewModel);
1288               viewModel.networkProxies(mapNetworkProxies(data));
1289               ko.applyBindings(viewModel,mainContent.find("#remote-repository-edit").get(0));
1290               activateRemoteRepositoryFormValidation(true);
1291               activatePopoverDoc();
1292             }
1293         })
1294       }
1295       if ($(e.target).attr("href")=="#remote-repositories-view") {
1296         $("#main-content" ).find("#remote-repository-edit-li" ).find("a").html($.i18n.prop("add"));
1297       }
1298
1299     });
1300
1301   }
1302
1303   loadManagedRepositories=function(successCallBackFn,errorCallBackFn){
1304     $.ajax("restServices/archivaServices/managedRepositoriesService/getManagedRepositories", {
1305         type: "GET",
1306         dataType: 'json',
1307         success: successCallBackFn,
1308         error: errorCallBackFn
1309     });
1310   }
1311
1312   loadRemoteRepositories=function(successCallBackFn,errorCallBackFn){
1313     $.ajax("restServices/archivaServices/remoteRepositoriesService/getRemoteRepositories", {
1314         type: "GET",
1315         dataType: 'json',
1316         success: successCallBackFn,
1317         error: errorCallBackFn
1318     });
1319   }
1320
1321   findManagedRepository=function(id,managedRepositories){
1322     var managedRepository=$.grep(managedRepositories,
1323                                     function(repo,idx){
1324                                       return repo.id()==id;
1325                                     }
1326                           );
1327     return ($.isArray(managedRepository) && managedRepository.length>0) ? managedRepository[0]:new ManagedRepository();
1328   }
1329
1330 });