]> source.dussan.org Git - archiva.git/commitdiff
start adding resources: archiva js template files
authorOlivier Lamy <olamy@apache.org>
Fri, 9 Dec 2011 12:24:11 +0000 (12:24 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 9 Dec 2011 12:24:11 +0000 (12:24 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1212365 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/WEB-INF/index.html [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main-tmpl.js [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/menu.html [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/message.html [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/topbar.html [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js [new file with mode: 0644]

diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/WEB-INF/index.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/WEB-INF/index.html
new file mode 100644 (file)
index 0000000..ede86f1
--- /dev/null
@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <link rel="stylesheet" href="css/aristo.css"/>
+  <link rel="stylesheet" href="css/bootstrap.min.1.4.0.css">
+
+  <script type="text/javascript" src="js/jquery-1.7.js"></script>
+
+  <script type="text/javascript" src="js/lab.js"></script>
+  <script type="text/javascript" src="js/require.1.0.1.js"></script>
+
+</head>
+
+<body style="padding-top: 40px;">
+
+<div id="topbar-menu-container"></div>
+
+<div class="container-fluid">
+  <div class="sidebar" id="sidebar-content"></div>
+
+  <div class="content">
+    <div class="row" id="user-messages"></div>
+
+    <div class="row" id="main-content"></div>
+  </div>
+</div>
+
+
+
+
+<div id="html-fragments" class="hide"></div>
+
+</body>
+
+<div id="dialog-confirm" title="" style="display: none">
+</div>
+
+<script type="text/javascript">
+    require.config({
+        baseUrl: "js/"
+      });
+    $LAB.setGlobalDefaults({AlwaysPreserveOrder:true,BasePath:"js/",explicit_preloading:false});
+    $LAB
+       .script("utils.js").wait()
+       .script("jquery.tmpl.js").wait()
+       .script("jquery.cookie.1.0.0.js").wait()
+       .script("knockout-debug.js").wait()
+       .script("jquery-ui-1.8.16.custom.min.js").wait()
+       .script("redback/register.js").wait()
+       .script("jquery.i18n.properties-1.0.9.js").wait()
+       .script("redback/i18nload.js").wait()
+       .script("jquery.validate.js").wait()
+       .script("jquery.json-2.3.min.js").wait()
+       .script("redback/operation.js").wait()
+       .script("main-tmpl.js").wait()
+       .script("redback/redback-tmpl.js").wait()
+       .script("bootstrap-modal.js").wait()
+       .script("bootstrap-alerts.js").wait()
+       .script("bootstrap-dropdown.js").wait()
+       .script("knockout.simpleGrid.js").wait()
+       .script("redback/user.js").wait()
+       .script("redback/users.js").wait()
+       .script("main.js");
+
+</script>
+
+</html>
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main-tmpl.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main-tmpl.js
new file mode 100644 (file)
index 0000000..43591b5
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2011 The Codehaus.
+ *
+ * Licensed 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.
+ */
+require(["text!templates/menu.html","text!templates/topbar.html","text!templates/message.html"],
+  function(menu,topbar,message) {
+
+    // template loading
+    $.tmpl( menu, $.i18n.map ).appendTo("#html-fragments");
+    $.tmpl( topbar, $.i18n.map ).appendTo("#html-fragments");
+    $("#html-fragments").append(message);
+    $.log("main-tmpl.js menu loaded");
+  }
+);
\ No newline at end of file
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js
new file mode 100644 (file)
index 0000000..8d65cd9
--- /dev/null
@@ -0,0 +1,219 @@
+/*
+ * Copyright 2011 The Codehaus.
+ *
+ * Licensed 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.
+ */
+require( ["order!jquery" ,"order!redback/redback"],
+function($) {
+
+  $(function() {
+
+    //$LAB.script("main-tmpl.js").wait(function(){
+      $.log("main karma");
+      customShowError=function(validator, errorMap, errorList) {
+        $( "div.clearfix" ).removeClass( "error" );
+        $( "span.help-inline" ).remove();
+        for ( var i = 0; errorList[i]; i++ ) {
+          var error = errorList[i];
+          var field = $("#"+error.element.id);
+          field.parents( "div.clearfix" ).addClass( "error" );
+          field.parent().append( "<span class=\"help-inline\">" + error.message + "</span>" )
+        }
+      }
+
+      /**
+       * return a user see user.js if user logged otherwise null
+       */
+      userLogged=function() {
+        // call /restServices/redbackServices/loginService/isLogged to know
+        // if a session exists and check the cookie
+        var userLogged = true;
+        $.ajax("/restServices/redbackServices/loginService/isLogged", {
+          type: "GET",
+          async: false,
+          success: function(data) {
+            userLogged = JSON.parse(data);
+          }
+        });
+        if (userLogged == false)
+        {
+          return null;
+        }
+        return jQuery.parseJSON($.cookie('redback_login'));
+      }
+
+      /**
+       * reccord a cookie for session with the logged user
+       * @param user see user.js
+       */
+      reccordLoginCookie=function(user) {
+        $.cookie('redback_login', ko.toJSON(user));
+      }
+
+      getUserFromLoginCookie=function(){
+        return $.parseJSON($.cookie('redback_login'));
+      }
+
+      deleteLoginCookie=function(){
+        $.cookie('redback_login', null);
+      }
+
+      logout=function(){
+        deleteLoginCookie();
+        $("#login-link").show();
+        $("#register-link").show();
+        $("#logout-link").hide();
+        $("#change-password-link").hide();
+        hideElementWithKarma();
+        screenChange();
+        $("#main-content").html("");
+        $.ajax({
+          url: '/restServices/redbackServices/loginService/logout'
+        });
+      }
+
+      decorateMenuWithKarma=function(user) {
+          var username = user.username;
+          // we can receive an observable user so take if it's a function or not
+          if ($.isFunction(username)){
+            username = user.username();
+          }
+          var url = '/restServices/redbackServices/userService/getCurrentUserOperations';
+          $.ajax({
+            url: url,
+            success: function(data){
+              var mappedOperations = $.map(data.operation, function(item) {
+                  return mapOperation(item);
+              });
+              window.redbackModel.operatioNames = $.map(mappedOperations, function(item){
+                return item.name;
+              });
+
+              $("[redback-permissions]").each(function(element){
+                var bindingValue = $(this).attr("redback-permissions");
+                $(this).hide();
+                var neededKarmas = $(eval(bindingValue)).toArray();
+                var karmaOk = false;
+                $(neededKarmas).each(function(value){
+                  //alert(neededKarmas[value]);
+                  if ($.inArray(neededKarmas[value],window.redbackModel.operatioNames)>=0) {
+                    karmaOk = true;
+                  }
+                });
+                if (karmaOk == false) {
+                  $(this).hide();
+                } else {
+                  $(this).show();
+                }
+              });
+            }
+          });
+        }
+
+      hideElementWithKarma=function(){
+        $("[redback-permissions]").each(function(element){
+          $(this).hide();
+        });
+      }
+
+
+      $('#topbar-menu-container').html($("#topbar-menu"));
+      $('#sidebar-content').html($("#main-menu"));
+
+
+      $.ajax("/restServices/redbackServices/userService/isAdminUserExists", {
+        type: "GET",
+        dataType: 'json',
+        success: function(data) {
+          var adminExists = JSON.parse(data);
+          if (adminExists == false) {
+            $("#create-admin-link").show();
+          }
+        }
+      });
+
+      hideElementWithKarma();
+
+      var user = userLogged();
+      if (!user) {
+        $("#login-link").show();
+        $("#register-link").show();
+        $("#change-password-link").hide();
+      } else {
+        $("#change-password-link").show();
+        $("#logout-link").show();
+        decorateMenuWithKarma(user);
+      }
+
+
+
+      /**
+       * display a success message
+       * @param text the success text
+       * @param idToAppend the id to append the success box
+       */
+      displaySuccessMessage=function(text,idToAppend){
+        var textId = idToAppend ? $("#"+idToAppend) : $("#user-messages");
+        $.tmpl($("#alert-message-success").html(), { "message" : text }).appendTo( textId );
+        $(textId).focus();
+      }
+
+      clearUserMessages=function(idToAppend){
+        var textId = idToAppend ? $("#"+idToAppend) : $("#user-messages");
+        $(textId).html('');
+      }
+
+      /**
+       * display an error message
+       * @param text the success text
+       * @param idToAppend the id to append the success box
+       */
+      displayErrorMessage=function(text,idToAppend){
+        var textId = idToAppend ? $("#"+idToAppend) : $("#user-messages");
+        $.tmpl($("#alert-message-error").html(), { "message" : text }).appendTo( textId );
+        $(textId).focus();
+      }
+
+      /**
+       * display a warning message
+       * @param text the success text
+       * @param idToAppend the id to append the success box
+       */
+      displayWarningMessage=function(text,idToAppend){
+        var textId = idToAppend ? $("#"+idToAppend) : $("#user-messages");
+        $.tmpl($("#alert-message-warning").html(), { "message" : text }).appendTo( textId );
+        $(textId).focus();
+      }
+
+      screenChange=function(){
+        clearUserMessages();
+      }
+
+      /**
+       * clear all input text and password found in the the selector
+       * @param selectorStr
+       */
+      clearForm=function(selectorStr){
+        $(selectorStr+" input[type='text']").each(function(ele){
+          $(this).val("");
+        });
+        $(selectorStr+" input[type='password']").each(function(ele){
+          $(this).val("");
+        });
+
+      }
+    });
+  //});
+
+});
+
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/menu.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/menu.html
new file mode 100644 (file)
index 0000000..79a633e
--- /dev/null
@@ -0,0 +1,7 @@
+
+  <div class='well' id="main-menu" redback-permissions="{permissions: ['archiva-manage-users']}" style="display: none">
+    <ul class="navigation">
+      <li style="display: none" redback-permissions="{permissions: ['archiva-manage-users']}"><a href="#" onclick="displayUsersGrid()">User List</a></li>
+      <li style="display: none" redback-permissions="{permissions: ['archiva-manage-users']}"><a href="#" onclick="displayRolesGrid()">Role List</a></li>
+    </ul>
+  </div>
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/message.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/message.html
new file mode 100644 (file)
index 0000000..e179c39
--- /dev/null
@@ -0,0 +1,19 @@
+<script id='alert-message-success' type='text/x-jquery-tmpl'>
+  <div class="alert-message fade in success">
+    <a class="close" href="#">×</a>
+    <p>${message}</p>
+  </div>
+</script>
+<script id='alert-message-error' type='text/x-jquery-tmpl'>
+  <div class="alert-message fade in error">
+    <a class="close" href="#">×</a>
+    <p>${message}</p>
+  </div>
+</script>
+<script id='alert-message-warning' type='text/x-jquery-tmpl'>
+  <div class="alert-message fade in warning">
+    <a class="close" href="#">×</a>
+    <p>${message}</p>
+  </div>
+</script>
+
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/topbar.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/topbar.html
new file mode 100644 (file)
index 0000000..704f530
--- /dev/null
@@ -0,0 +1,37 @@
+<div id="topbar-menu">
+<div class="topbar-wrapper" style="z-index: 5;">
+<div class="topbar" data-dropdown="dropdown">
+  <div class="topbar-inner">
+    <div class="container-fluid">
+      <h4 class="brand"><a href="/index.html">Redback</a></h4>
+      <ul class="nav secondary-nav">
+        <li id="create-admin-link" style="display: none">
+          <a href="#" onclick="adminCreateBox();">Admin User Creation</a>
+        </li>
+        <li id="login-link" style="display: none">
+          <a href="#" onclick="loginBox();">
+            <span class="label success">${login}</span>
+          </a>
+        </li>
+        <li id="change-password-link" style="">
+          <a href="#" onclick="editUserDetailsBox();">Edit Informations</a>
+        </li>
+        <li id="logout-link" style="display: none">
+          <a href="#" onclick="logout();">
+            <span class="label important">${logout}</span>
+          </a>
+        </li>
+        <li id="register-link" style="display: none">
+          <a href="#" onclick="registerBox();">
+            <span class="label notice">${register}</span>
+          </a>
+        </li>
+      </ul>
+      <form class="pull-right" action="">
+        <input type="text" placeholder="Search" />
+      </form>
+    </div>
+  </div>
+</div>
+</div>
+</div>
\ No newline at end of file
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js
new file mode 100644 (file)
index 0000000..b3b0cdc
--- /dev/null
@@ -0,0 +1,15 @@
+$.log = (function(message) {
+  if (typeof window.console != 'undefined' && typeof window.console.log != 'undefined') {
+    console.log(message);
+  } else {
+    // do nothing no console
+  }
+});
+
+$.urlParam = function(name){
+    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
+    if (results) {
+      return results[1] || 0;
+    }
+    return null;
+}
\ No newline at end of file