cleanup small js files.

defined a js files as a module for require js.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1305650 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-03-26 22:50:15 +00:00
parent 45018e30d3
commit d556ce5072
17 changed files with 176 additions and 267 deletions

View File

@ -64,7 +64,18 @@
"jquery_json": "jquery.json-2.3.min",
"knockout.simpleGrid": "knockout.simpleGrid",
"knockout": "knockout-2.0.0.debug",
"knockout.sortable": "knockout-sortable"
"knockout.sortable": "knockout-sortable",
"redback": "redback/redback",
"general-admin":"archiva/general-admin",
"redback-templates": "redback/redback-tmpl",
"main-templates": "archiva/main-tmpl",
"repositories": "archiva/repositories",
"network-proxies": "archiva/network-proxies",
"proxy-connectors": "archiva/proxy-connectors",
"repository-groups": "archiva/repository-groups",
"roles": "redback/roles",
"user": "redback/user",
"users": "redback/users"
}
// file upload dependencies
//.script("jquery.iframe-transport-1.4.js").wait()
@ -72,7 +83,7 @@
//.script("jquery.fileupload-ip-1.0.6.js").wait()
//.script("jquery.fileupload-ui-6.6.3.js" ).wait()
});
require(['domReady','jquery','i18n','startup'], function (domReady) {
require(['order!domReady','order!jquery','order!i18n','order!startup'], function (domReady) {
domReady.withResources(function () {
loadi18n();
$.ajax(
@ -84,15 +95,6 @@
window.archivaJavascriptLog=data.javascriptLog;
window.archivaRuntimeInfo=data;
require.config({
baseUrl: "js/",
urlArgs: "_="+new Date().getTime(),
"paths": {
"redback": buildLoadJsUrl("redback/redback.js")
}
});
// CacheBust is for dev purpose use false in prod env !
var options = {
AlwaysPreserveOrder:true,
@ -102,20 +104,6 @@
};
$LAB.setGlobalDefaults(options);
$LAB
.script(buildLoadJsUrl("archiva/main-tmpl.js")).wait()
.script(buildLoadJsUrl("archiva/general-admin.js"))
.script(buildLoadJsUrl("archiva/repositories.js")).wait()
.script(buildLoadJsUrl("archiva/network-proxies.js")).wait()
.script(buildLoadJsUrl("archiva/proxy-connectors.js")).wait()
.script(buildLoadJsUrl("redback/operation.js")).wait()
.script(buildLoadJsUrl("archiva/repository-groups.js")).wait()
.script(buildLoadJsUrl("redback/redback-tmpl.js")).wait()
.script(buildLoadJsUrl("redback/user.js")).wait()
.script(buildLoadJsUrl("redback/users.js")).wait()
.script(buildLoadJsUrl("redback/register.js")).wait()
.script(buildLoadJsUrl("redback/permission.js")).wait()
.script(buildLoadJsUrl("redback/resource.js")).wait()
.script(buildLoadJsUrl("redback/roles.js")).wait()
.script(buildLoadJsUrl("archiva/main.js"));
}
})

View File

@ -16,7 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
$(function() {
define("general-admin",["jquery","i18n","order!utils","order!jquery_tmpl","order!knockout","jquery_validate","bootstrap"]
, function() {
//-------------------------
// legacy path part
@ -822,4 +823,5 @@ $(function() {
}
});
}
});

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
require(["text!js/archiva/templates/menu.html"+appendTemplateUrl(),
define("main-templates",["text!js/archiva/templates/menu.html"+appendTemplateUrl(),
"text!js/archiva/templates/message.html"+appendTemplateUrl(),
"text!js/archiva/templates/modal.html"+appendTemplateUrl(),
"text!js/archiva/templates/grids-generics.html"+appendTemplateUrl(),
@ -25,7 +25,8 @@ require(["text!js/archiva/templates/menu.html"+appendTemplateUrl(),
"text!js/archiva/templates/proxy-connectors.html"+appendTemplateUrl(),
"text!js/archiva/templates/repository-groups.html"+appendTemplateUrl(),
"text!js/archiva/templates/search.html"+appendTemplateUrl(),
"text!js/archiva/templates/general-admin.html"+appendTemplateUrl()],
"text!js/archiva/templates/general-admin.html"+appendTemplateUrl(),
"jquery_tmpl","utils"],
function(menu,message,modal,grids_generics,repositories,network_proxies,proxies_connectors,
repository_groups,search,general_admin) {

View File

@ -17,10 +17,12 @@
* under the License.
*/
require( ["order!jquery","jquery_ui","jquery_cookie","bootstrap","order!archiva/search",
"jquery_validate","jquery_json","order!knockout","order!redback/redback"],
"jquery_validate","jquery_json","order!knockout","order!redback-templates","order!main-templates","order!roles",
"order!redback","general-admin","repositories","network-proxies","proxy-connectors","repository-groups"],
function() {
// define a container object with various datas
window.archivaModel = {};

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
$(function() {
define("network-proxies",["jquery","i18n","jquery_tmpl","bootstrap","jquery_validate"], function() {
NetworkProxy=function(id,protocol,host,port,username,password,useNtlm){

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
$(function() {
define("proxy-connectors",["jquery","i18n","jquery_tmpl","bootstrap","jquery_validate"], function() {
ProxyConnector=function(sourceRepoId,targetRepoId,proxyId,blackListPatterns,whiteListPatterns,policiesEntries,propertiesEntries,
disabled,order){

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
$(function() {
define("repositories",["jquery","i18n","jquery_tmpl","bootstrap","jquery_validate"], function() {
// FIXME this must be dynamic if we do a plugin mechanism with dynamic repositories types
// FIXME i18n

View File

@ -16,7 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
$(function() {
define("repository-groups",["jquery","i18n","jquery_tmpl","bootstrap","jquery_validate","jquery_ui"],
function() {
RepositoryGroup=function(id,repositories){

View File

@ -1,34 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
$(function() {
Operation=function(name) {
this.name=ko.observable(name);
}
/**
* @param data Operation response from redback rest api
*/
mapOperation=function(data) {
return new Operation(data.name,null);
}
});

View File

@ -1,38 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
$(function() {
Permission=function(name,operation,resource) {
this.name=ko.observable(name);
this.operation=ko.observable(operation);
this.resource=ko.observable(resource);
}
/**
* @param data Permission response from redback rest api
*/
mapPermission=function(data) {
return new Permission(data.name,
data.operation?mapOperation(data.operation):null,
data.resource?mapResource(data.resource):null);
}
});

View File

@ -16,13 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
require(["text!js/redback/templates/user-edit.html"+appendTemplateUrl(),
define("redback-templates",["text!js/redback/templates/user-edit.html"+appendTemplateUrl(),
"text!js/redback/templates/user-grids.html"+appendTemplateUrl(),
"text!js/redback/templates/login.html"+appendTemplateUrl(),
"text!js/redback/templates/register-form.html"+appendTemplateUrl(),
"text!js/redback/templates/password-change-form.html"+appendTemplateUrl(),
"text!js/redback/templates/user-edit-form.html"+appendTemplateUrl(),
"text!js/redback/templates/roles-tmpl.html"+appendTemplateUrl()],
"text!js/redback/templates/roles-tmpl.html"+appendTemplateUrl(),
"jquery_tmpl","utils"],
function(useredit, usergrids, login,register,passwordchange,usereditform,roles) {
var htmlFragment=$("#html-fragments");

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
$(function() {
define("redback",["jquery","order!utils","jquery_validate","jquery_json","roles","user","users"], function() {
// define a container object with various datas
window.redbackModel = {userOperationNames:null,key:null,i18n:$.i18n.map};
@ -50,4 +50,146 @@ $(function() {
});
}
Operation=function(name) {
this.name=ko.observable(name);
}
/**
* @param data Operation response from redback rest api
*/
mapOperation=function(data) {
return new Operation(data.name,null);
}
Permission=function(name,operation,resource) {
this.name=ko.observable(name);
this.operation=ko.observable(operation);
this.resource=ko.observable(resource);
}
/**
* @param data Permission response from redback rest api
*/
mapPermission=function(data) {
return new Permission(data.name,
data.operation?mapOperation(data.operation):null,
data.resource?mapResource(data.resource):null);
}
Resource=function(identifier,pattern) {
this.identifier=ko.observable(identifier);
this.pattern=ko.observable(pattern);
}
/**
* @param data Resource response from redback rest api
*/
mapResource=function(data) {
return new Resource(data.identifier,data.pattern);
}
//---------------------------------------
// register part
//---------------------------------------
/**
* open the register modal box
*/
registerBox=function(){
if (window.modalRegisterWindow==null) {
window.modalRegisterWindow = $("#modal-register").modal({backdrop:'static',show:false});
window.modalRegisterWindow.bind('hidden', function () {
$("#modal-register-err-message").hide();
})
}
window.modalRegisterWindow.modal('show');
$("#user-register-form").validate({
showErrors: function(validator, errorMap, errorList) {
customShowError("#user-register-form",validator,errorMap,errorMap);
}
});
$("#modal-register").delegate("#modal-register-ok", "click keydown keypress", function(e) {
e.preventDefault();
register();
});
//$("#modal-register").focus();
}
/**
* validate the register form and call REST service
*/
register=function(){
$.log("register.js#register");
var valid = $("#user-register-form").valid();
if (!valid) {
return;
}
clearUserMessages();
$("#modal-register-ok").attr("disabled","disabled");
$('#modal-register-footer').append(smallSpinnerImg());
var user = {};
user.username = $("#user-register-form-username").val();
user.fullName = $("#user-register-form-fullname").val();
user.email = $("#user-register-form-email").val();
jQuery.ajax({
url: 'restServices/redbackServices/userService/registerUser',
data: JSON.stringify(user),
type: 'POST',
contentType: "application/json",
success: function(result){
var registered = false;
if (result == "-1") {
registered = false;
} else {
registered = true;
}
if (registered == true) {
window.modalRegisterWindow.modal('hide');
$("#register-link").hide();
// FIXME i18n
displaySuccessMessage("registered your key has been sent");
}
},
complete: function(){
$("#modal-register-ok").removeAttr("disabled");
removeSmallSpinnerImg();
},
error: function(result) {
var obj = jQuery.parseJSON(result.responseText);
displayRedbackError(obj);
window.modalRegisterWindow.modal('hide');
}
})
}
/**
* validate a registration key and go to change password key
* @param key
*/
validateKey=function(key,registration) {
// FIXME spinner display
$.ajax({
url: 'restServices/redbackServices/userService/validateKey/'+key,
type: 'GET',
success: function(result){
window.redbackModel.key=key;
$.log("validateKey#sucess");
changePasswordBox(false,registration?registration:true,null);
},
complete: function(){
// hide spinner
},
error: function(result) {
$.log("validateKey#error");
var obj = jQuery.parseJSON(result.responseText);
$.log("validateKey#error response:"+obj);
displayRedbackError(obj);
}
})
}
});

View File

@ -1,121 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
$(function() {
/**
* open the register modal box
*/
registerBox=function(){
if (window.modalRegisterWindow==null) {
window.modalRegisterWindow = $("#modal-register").modal({backdrop:'static',show:false});
window.modalRegisterWindow.bind('hidden', function () {
$("#modal-register-err-message").hide();
})
}
window.modalRegisterWindow.modal('show');
$("#user-register-form").validate({
showErrors: function(validator, errorMap, errorList) {
customShowError("#user-register-form",validator,errorMap,errorMap);
}
});
$("#modal-register").delegate("#modal-register-ok", "click keydown keypress", function(e) {
e.preventDefault();
register();
});
//$("#modal-register").focus();
}
/**
* validate the register form and call REST service
*/
register=function(){
$.log("register.js#register");
var valid = $("#user-register-form").valid();
if (!valid) {
return;
}
clearUserMessages();
$("#modal-register-ok").attr("disabled","disabled");
$('#modal-register-footer').append(smallSpinnerImg());
var user = {};
user.username = $("#user-register-form-username").val();
user.fullName = $("#user-register-form-fullname").val();
user.email = $("#user-register-form-email").val();
jQuery.ajax({
url: 'restServices/redbackServices/userService/registerUser',
data: '{"user":'+JSON.stringify(user)+'}',
type: 'POST',
contentType: "application/json",
success: function(result){
var registered = false;
if (result == "-1") {
registered = false;
} else {
registered = true;
}
if (registered == true) {
window.modalRegisterWindow.modal('hide');
$("#register-link").hide();
// FIXME i18n
displaySuccessMessage("registered your key has been sent");
}
},
complete: function(){
$("#modal-register-ok").removeAttr("disabled");
removeSmallSpinnerImg();
},
error: function(result) {
var obj = jQuery.parseJSON(result.responseText);
displayRedbackError(obj);
window.modalRegisterWindow.modal('hide');
}
})
}
/**
* validate a registration key and go to change password key
* @param key
*/
validateKey=function(key,registration) {
// FIXME spinner display
$.ajax({
url: 'restServices/redbackServices/userService/validateKey/'+key,
type: 'GET',
success: function(result){
window.redbackModel.key=key;
$.log("validateKey#sucess");
changePasswordBox(false,registration?registration:true,null);
},
complete: function(){
// hide spinner
},
error: function(result) {
$.log("validateKey#error");
var obj = jQuery.parseJSON(result.responseText);
$.log("validateKey#error response:"+obj);
displayRedbackError(obj);
}
})
}
});

View File

@ -1,35 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
$(function() {
Resource=function(identifier,pattern) {
this.identifier=ko.observable(identifier);
this.pattern=ko.observable(pattern);
}
/**
* @param data Resource response from redback rest api
*/
mapResource=function(data) {
return new Resource(data.identifier,data.pattern);
}
});

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
$(function() {
define("roles",["jquery","order!utils","i18n","jquery_validate","order!knockout","order!knockout.simpleGrid"], function() {
Role = function(name,description,assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions,otherUsers){

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
$(function() {
define("user",["jquery","order!utils","i18n","jquery_validate","order!knockout","order!knockout.simpleGrid"], function() {
/**
* object model for user with some function to create/update/delete users

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
$(function() {
define("users",["jquery","order!utils","i18n","jquery_validate","order!knockout","order!knockout.simpleGrid"], function() {
/**
* view model used for users grid