Commit b7a631ae authored by Thomas Lechauve's avatar Thomas Lechauve

Reorganizing vifib project in order to use grunt

parent 1e09fe28
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="static/css/bootstrap.min.css" rel="stylesheet"/>
<script id="form.new.instance" type="text/html">
<article>
<form class="form-horizontal">
<fieldset>
<legend>Request a new instance</legend>
<div class="control-group">
<label class="control-label">Name</label>
<div class="controls">
<input type="text" class="input-large" required name="title"/>
</div>
</div>
<div class="control-group">
<label class="control-label">Software release</label>
<div class="controls">
<input type="text" class="input-xlarge" required name="software_release"/>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary" name="submit">Request</button>
</div>
</fieldset>
</form>
</article>
</script>
<script id="auth" type="text/html">
<article>
<p>Authentification needed. Are you agree to be redirect to login ?</p>
<a href="http://{{ host }}?response_type=token&client_id={{ client_id }}&redirect_uri={{ redirect }}">Redirect</a>
</article>
</script>
<script id="service" type="text/html">
{{! Service page template }}
<article>
<form class="form-horizontal">
<fieldset>
<legend>
{{ instance_id }}
<div class="pull-right">
<div class="btn">Bang</div>
<div class="btn">Destroy</div>
<div class="btn">Certificates</div>
</div>
</legend>
<div class="control-group">
<label class="control-label">Reference</label>
<div class="controls">
<span class="uneditable-input">{{ instance_id }}</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Software release</label>
<div class="controls">
<span class="uneditable-input">{{ software_release }}</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Software type</label>
<div class="controls">
<span class="uneditable-input">{{ software_type }}</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Status</label>
<div class="controls">
<div class="btn-group">
<button class="btn">Stop</button>
<button class="btn btn-success disabled">Started</button>
</div>
</div>
</div>
</fieldset>
</form>
<table class="table">
<caption>Connection parameters</caption>
{{# connection}}
<tr><td>key</td><td>{{ key }}</td></tr>
{{/ connection}}
</table>
<form>
<fieldset>
<legend>
Parameter XML
<div class="pull-right">
<button type="submit" class="btn btn-primary">Save changes</button>
<button class="btn">Cancel</button>
</div>
</legend>
<textarea name="xml" style="width: 98%; height: 110px;">
<?xml version="1.0" encoding="utf-8"?>
<instance>
<parameter id="nbd_ip">2a01:e35:2e27:460:e2cb:4eff:fed9:48dc</parameter>
<parameter id="nbd_port">1024</parameter>
</instance>
</textarea>
</fieldset>
</form>
</article>
</script>
<script id="simple-form" type="text/html">
<form class="form-inline">
<fieldset>
<div class="input-append">
<input required class="span2" size="16" type="text"/>
<button class="btn" type="submit">Go !</button>
</div>
</fieldset>
</form>
</script>
<script id="service-error" type="text/html">
<div class="alert alert-error" style="text-align: center;">
<h4>Service : {{ id }} not found !</h4>
</div>
</script>
</head>
<body>
<div class="navbar">
<div class="navbar-inner">
<div class="container-fluid">
<div class="row-fluid">
<div class="span2">
<!--<a href="#" class="brand">Vifib</a>-->
<img src="static/img/vifib_logo.gray.png" style="max-height: 40px" />
</div>
<div class="span10">
<ul class="nav">
<li><a href="#">Dashboard</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<div class="well">
<ul class="nav nav-list">
<li class="nav-header">Servers</li>
<li autofocus="autofocus"><a href="#computers"><i class="icon-list"></i>List all servers</a></li>
<li><a href="#/computer"><i class="icon-plus-sign"></i>Add new server</a></li>
<li><a href="#/computer/comp-1"><i class="icon-"></i>Comp-1</a></li>
<li class="nav-header">Services</li>
<li><a href="#/services"><i class="icon-list"></i>List all services</a></li>
<li><a href="#/service"><i class="icon-plus-sign"></i>Add new service</a></li>
<li><a href="#/service/200"><i class="icon-"></i>inst-0</a></li>
<li><a href="#/service/401"><i class="icon-"></i>inst-1</a></li>
<li class="nav-header">Account</li>
<li><a href="#/invoices"><i class="icon-inbox"></i>Invoices</a></li>
<li><a href="#/settings"><i class="icon-cog"></i>Settings</a></li>
<!--<li class="nav-header">Quick search</li>-->
<!--<li><form class="form-search">
<i class="icon-search"></i>
<input type="text" class="input-mini search-query">
</form></li>-->
</ul>
</div>
</div>
<section class="span9" id="main">
<!--Body content-->
</section>
</div>
</div>
<script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="static/js/ICanHaz.min.js"></script>
<script type="text/javascript" src="static/js/modernizr-2.5.3.js"></script>
<script type="text/javascript" src="static/js/sinon-1.3.2.js"></script>
<script type="text/javascript" src="static/js/jquery.slapos.js"></script>
<!--<script type="text/javascript" src="static/js/fake.js"></script>-->
<script type="text/javascript" src="static/js/urlHandler.js"></script>
<script type="text/javascript" src="static/js/form.js"></script>
</body>
</html>
This diff is collapsed.
(function(){var q=function(){function c(a){return(""+a).replace(/&(?!\w+;)|[<>"']/g,function(a){return k[a]||a})}var e=Object.prototype.toString;Array.isArray=Array.isArray||function(a){return"[object Array]"==e.call(a)};var i=String.prototype.trim,g;if(i)g=function(a){return null==a?"":i.call(a)};else{var h,m;/\S/.test("\u00a0")?(h=/^[\s\xA0]+/,m=/[\s\xA0]+$/):(h=/^\s+/,m=/\s+$/);g=function(a){return null==a?"":a.toString().replace(h,"").replace(m,"")}}var k={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;",
"'":"&#39;"},o={},p=function(){};p.prototype={otag:"{{",ctag:"}}",pragmas:{},buffer:[],pragmas_implemented:{"IMPLICIT-ITERATOR":!0},context:{},render:function(a,d,b,f){if(!f)this.context=d,this.buffer=[];if(this.includes("",a)){var a=this.render_pragmas(a),j=this.render_section(a,d,b);!1===j&&(j=this.render_tags(a,d,b,f));if(f)return j;this.sendLines(j)}else{if(f)return a;this.send(a)}},send:function(a){""!==a&&this.buffer.push(a)},sendLines:function(a){if(a)for(var a=a.split("\n"),d=0;d<a.length;d++)this.send(a[d])},
render_pragmas:function(a){if(!this.includes("%",a))return a;var d=this,b=this.getCachedRegex("render_pragmas",function(a,d){return RegExp(a+"%([\\w-]+) ?([\\w]+=[\\w]+)?"+d,"g")});return a.replace(b,function(a,b,e){if(!d.pragmas_implemented[b])throw{message:"This implementation of mustache doesn't understand the '"+b+"' pragma"};d.pragmas[b]={};e&&(a=e.split("="),d.pragmas[b][a[0]]=a[1]);return""})},render_partial:function(a,d,b){a=g(a);if(!b||void 0===b[a])throw{message:"unknown_partial '"+a+"'"};
return!d||"object"!=typeof d[a]?this.render(b[a],d,b,!0):this.render(b[a],d[a],b,!0)},render_section:function(a,d,b){if(!this.includes("#",a)&&!this.includes("^",a))return!1;var f=this,j=this.getCachedRegex("render_section",function(a,b){return RegExp("^([\\s\\S]*?)"+a+"(\\^|\\#)\\s*(.+)\\s*"+b+"\n*([\\s\\S]*?)"+a+"\\/\\s*\\3\\s*"+b+"\\s*([\\s\\S]*)$","g")});return a.replace(j,function(a,j,e,c,g,h){var a=j?f.render_tags(j,d,b,!0):"",h=h?f.render(h,d,b,!0):"",n,c=f.find(c,d);"^"===e?n=!c||Array.isArray(c)&&
0===c.length?f.render(g,d,b,!0):"":"#"===e&&(n=Array.isArray(c)?f.map(c,function(a){return f.render(g,f.create_context(a),b,!0)}).join(""):f.is_object(c)?f.render(g,f.create_context(c),b,!0):"function"==typeof c?c.call(d,g,function(a){return f.render(a,d,b,!0)}):c?f.render(g,d,b,!0):"");return a+n+h})},render_tags:function(a,d,b,f){for(var j=this,e=function(){return j.getCachedRegex("render_tags",function(a,b){return RegExp(a+"(=|!|>|&|\\{|%)?([^#\\^]+?)\\1?"+b+"+","g")})},g=e(),h=function(a,f,h){switch(f){case "!":return"";
case "=":return j.set_delimiters(h),g=e(),"";case ">":return j.render_partial(h,d,b);case "{":case "&":return j.find(h,d);default:return c(j.find(h,d))}},a=a.split("\n"),i=0;i<a.length;i++)a[i]=a[i].replace(g,h,this),f||this.send(a[i]);if(f)return a.join("\n")},set_delimiters:function(a){a=a.split(" ");this.otag=this.escape_regex(a[0]);this.ctag=this.escape_regex(a[1])},escape_regex:function(a){if(!arguments.callee.sRE)arguments.callee.sRE=RegExp("(\\/|\\.|\\*|\\+|\\?|\\||\\(|\\)|\\[|\\]|\\{|\\}|\\\\)",
"g");return a.replace(arguments.callee.sRE,"\\$1")},find:function(a,d){function b(a){return!1===a||0===a||a}var a=g(a),f;if(a.match(/([a-z_]+)\./ig)){var c=this.walk_context(a,d);b(c)&&(f=c)}else b(d[a])?f=d[a]:b(this.context[a])&&(f=this.context[a]);return"function"==typeof f?f.apply(d):void 0!==f?f:""},walk_context:function(a,d){for(var b=a.split("."),f=void 0!=d[b[0]]?d:this.context,c=f[b.shift()];void 0!=c&&0<b.length;)f=c,c=c[b.shift()];return"function"==typeof c?c.apply(f):c},includes:function(a,
d){return-1!=d.indexOf(this.otag+a)},create_context:function(a){if(this.is_object(a))return a;var d=".";if(this.pragmas["IMPLICIT-ITERATOR"])d=this.pragmas["IMPLICIT-ITERATOR"].iterator;var b={};b[d]=a;return b},is_object:function(a){return a&&"object"==typeof a},map:function(a,d){if("function"==typeof a.map)return a.map(d);for(var b=[],c=a.length,e=0;e<c;e++)b.push(d(a[e]));return b},getCachedRegex:function(a,d){var b=o[this.otag];b||(b=o[this.otag]={});var c=b[this.ctag];c||(c=b[this.ctag]={});
(b=c[a])||(b=c[a]=d(this.otag,this.ctag));return b}};return{name:"mustache.js",version:"0.4.0",to_html:function(a,c,b,f){var e=new p;if(f)e.send=f;e.render(a,c||{},b);if(!f)return e.buffer.join("\n")}}}();(function(){var c={VERSION:"0.10",templates:{},$:"undefined"!==typeof window?window.jQuery||window.Zepto||null:null,addTemplate:function(e,i){if("object"===typeof e)for(var g in e)this.addTemplate(g,e[g]);else c[e]?console.error("Invalid name: "+e+"."):c.templates[e]?console.error('Template "'+e+
' " exists'):(c.templates[e]=i,c[e]=function(g,i){var g=g||{},k=q.to_html(c.templates[e],g,c.templates);return c.$&&!i?c.$(k):k})},clearAll:function(){for(var e in c.templates)delete c[e];c.templates={}},refresh:function(){c.clearAll();c.grabTemplates()},grabTemplates:function(){var e,i=document.getElementsByTagName("script"),g,h=[];for(e=0,l=i.length;e<l;e++)if((g=i[e])&&g.innerHTML&&g.id&&("text/html"===g.type||"text/x-icanhaz"===g.type))c.addTemplate(g.id,"".trim?g.innerHTML.trim():g.innerHTML.replace(/^\s+/,
"").replace(/\s+$/,"")),h.unshift(g);for(e=0,l=h.length;e<l;e++)h[e].parentNode.removeChild(h[e])}};"undefined"!==typeof require?module.exports=c:window.ich=c;"undefined"!==typeof document&&(c.$?c.$(function(){c.grabTemplates()}):document.addEventListener("DOMContentLoaded",function(){c.grabTemplates()},!0))})()})();
var comp0 = {computer_id: "COMP-0",
software: [{software_release: "http://example.com/example.cfg",status: "install"}],
partition: [
{title: "slapart1",
instance_id: "foo",
status: "start",
software_release: "http://example.com/example.cfg"},
{title: "slapart2",
instance_id: "bar",
status: "stop",
software_release: "http://example.com/example.cfg"}
]
};
var comp1 = {computer_id: "COMP-1",
software: [{software_release: "http://example.com/example.cfg",status: "install"}],
partition: [
{title: "slapart1",
instance_id: "foo",
status: "start",
software_release: "http://example.com/example.cfg"},
{title: "slapart2",
instance_id: "bar",
status: "stop",
software_release: "http://example.com/example.cfg"}
]
};
var inst0 =
{instance_id: "INST-0",
status: "start",
software_release: "http://example.com/example.cfg",
software_type: "type_provided_by_the_software",
slave: "False",
connection: [{
custom_connection_parameter_1: "foo",
custom_connection_parameter_2: "bar"}],
parameter: {
Custom1: "one string",
Custom2: "one float",
Custom3: ["abc", "def"]},
sla: {computer_id: "COMP-0"},
children_id_list: ["subinstance1", "subinstance2"],
partition: {
public_ip: ["::1", "91.121.63.94"],
private_ip: ["127.0.0.1"],
tap_interface: "tap2"}
};
var inst1 =
{instance_id: "INST-1",
status: "start",
software_release: "http://example.com/example.cfg",
software_type: "type_provided_by_the_software",
slave: "False",
connection: [{
key: "foo",
key: "bar"}],
parameter: {
Custom1: "one string",
Custom2: "one float",
Custom3: ["abc", "def"]},
sla: {computer_id: "COMP-0"},
children_id_list: ["subinstance1", "subinstance2"],
partition: {
public_ip: ["::1", "91.121.63.94"],
private_ip: ["127.0.0.1"],
tap_interface: "tap2"}
};
var fakeserver = sinon.fakeServer.create();
// Get instance
/*fakeserver.respondWith("GET", "/instance/200",[200, {"Content-Type":"application/json; charset=utf-8"}, JSON.stringify(inst0)]);
fakeserver.respondWith("GET", "/instance/201",[200, {"Content-Type":"application/json; charset=utf-8"}, JSON.stringify(inst1)]);
// Get instance FAIL
fakeserver.respondWith("GET", "/instance/408",[408, {"Content-Type":"application/json; charset=utf-8"}, "NOT FOUND"]);
fakeserver.respondWith("POST", "/instance",[401, {"Content-Type":"application/json; charset=utf-8"}, "NEED AUTH"]);
var tmp = $.ajax;
$.ajax = function(url, options){
var result = tmp(url, options);
fakeserver.respond();
return result;
}*/
/**
* NEXEDI
* Author: Thomas Lechauve
* Date: 4/17/12
*/
(function($) {
var routes = {
"/service" : "displayForm",
"/service/:id" : "displayData"
}
var router = function(e, d){
var $this = $(this);
$.each(routes, function(pattern, callback){
pattern = pattern.replace(/:\w+/g, '([^\/]+)');
var regex = new RegExp('^' + pattern + '$');
var result = regex.exec(d);
if (result) {
result.shift();
methods[callback].apply($this, result);
}
});
}
var methods = {
init: function() {
// Initialize slapos in this context
$(this).slapos({host: '10.0.1.139:12002/erp5/portal_vifib_rest_api_v1'});
var $this = $(this);
// Bind to urlChange event
return this.each(function(){
$.subscribe("urlChange", function(e, d){
router.call($this, e, d);
});
$.subscribe("auth", function(e, d){
$(this).form("authenticate", d);
});
});
},
authenticate: function(data) {
for (var d in data) {
if (data.hasOwnProperty(d)) {
$(this).slapos('store', d, data[d]);
}
}
},
displayData: function(id){
var redirect = function(){
$(this).form('render', 'auth', {
'host':'t139:12002/erp5/web_site_module/hosting/request-access-token',
'client_id': 'client',
'redirect':escape(window.location.href)
})
};
var statusCode = {
401: redirect
};
$(this).html("<p>Ajax loading...</p>")
.slapos('getInstance', id, function(data){
$(this).form('render', 'service', data);
}, statusCode);
},
displayForm: function() {
$(this).form('render', 'form.new.instance');
var data = {};
$(this).find("form").submit(function(){
$(this).find('input').serializeArray().map(function(elem){
data[elem["name"]] = elem["value"];
});
$(this).form('displayAsking', data);
return false;
});
},
displayAsking: function(data){
var request = {
software_type: "type_provided_by_the_software",
slave: false,
status: "started",
parameter: {
Custom1: "one string",
Custom2: "one float",
Custom3: ["abc", "def"],
},
sla: {
computer_id: "COMP-0",
}
};
var redirect = function(){
$(this).form('render', 'auth', {
'host':'t139:12002/erp5/web_site_module/hosting/request-access-token',
'client_id': 'client',
'redirect':escape(window.location.href)
})
};
var statusCode = {
401: redirect
};
$.extend(request, data);
$(this).html("<p>Requesting a new instance "+request["title"]+" ...</p>")
.slapos('newInstance', request, function(data){
$(this).html(data);},
statusCode
);
},
render: function(template, data){
$(this).html(ich[template](data, true));
}
};
$.fn.form = function(method){
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.form' );
}
};
})(jQuery);
$("#main").form();
This diff is collapsed.
../../../jquery.slapos/src/jquery.slapos.js
\ No newline at end of file
This diff is collapsed.
/**
* NEXEDI
* Author: Thomas Lechauve
* Date: 4/24/12
*/
var o = [];
;(function($){
$.keysName = { "down": 40, "up": 38, "tab": 9 };
var selectors = "a, input";
var methods = {
init: function(key){
if( key == undefined ) {
$(this).addClass("shortcutable");
o.push($(this)[0]);
return $(this).shortcuts('list');
} else {
return $(this).shortcuts('bindKey', key);
}
},
bindKey: function(key){
return this.each(function(){
var $this = $(this);
$(document).bind('keydown', function(e){
if( e.keyCode == ($.isNumeric(key) ? key : $.keysName[key]) ) {
e.preventDefault();
$this.focus();
}
});
});
},
list: function(){
return this.each(function(){
$(this).bind('keydown', function(e){
if( e.keyCode == $.keysName["down"] ){
$(this).shortcuts('nextChild');
} else if (e.keyCode == $.keysName["up"] ){
$(this).shortcuts('prevChild');
} else if (e.keyCode == $.keysName["tab"] ) {
e.preventDefault();
if ( e.shiftKey ) {
$(this).shortcuts('prev').find(selectors).first().focus();
} else {
$(this).shortcuts('next').find(selectors).first().focus();
}
}
});
$(this).find('a').first().focus().select();
});
},
nextChild: function(){
return this.each(function(){
if( $(document.activeElement).parents('.shortcutable').is(':last-child') ) {
$(document.activeElement).grandma().find(selectors).first().focus();
} else {
$(document.activeElement).parent().next().find(selectors).focus();
}
});
},
prevChild: function(){
return this.each(function(){
if( $(document.activeElement).parent().is(':first-child') ) {
$(document.activeElement).grandma().find(selectors).last().focus();
} else {
$(document.activeElement).parent().prev().find(selectors).focus();
}
});
},
next: function(){
return $(o[($.inArray( $(this)[0], o) + 1 ) % o.length]);
},
prev: function(){
var i = $.inArray($(this)[0], o);
return $( o[ ( i <= 0 ? o.length - 1 : i - 1 )]);
}
};
$.fn.shortcuts = function(method){
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method || $.isNumeric(method)) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.shortcuts' );
}
};
$.fn.grandma = function(){
var e = this.parent().parent();
return this.pushStack( e.get() );
};
})(jQuery);
This diff is collapsed.
/**
* NEXEDI
* Author: Thomas Lechauve
* Date: 4/18/12
*/
// Hash parser utility
$.parseHash = function(hashTag) {
var tokenized = $.extractAuth(hashTag);
if (tokenized) {
$.publish('auth', tokenized);
return hashTag.split("&")[0]
}
return hashTag
};
$.extractAuth = function (hashTag) {
var del = hashTag.indexOf('&');
if (del != -1) {
var splitted = hashTag.substring(del+1).split('&');
var result = {};
for (p in splitted) {
var s = splitted[p].split('=');
result[s[0]] = s[1];
}
return result;
}
return false;
};
$.genHash = function(url) {
return '/' + url.join('/');
};
/* Pub / Sub Pattern
WARNING
What's happening when we destroy a DOM object subscribed ?
*/
var o = $({});
$.subscribe = function() {
o.on.apply(o, arguments);
};
$.unsubscribe = function() {
o.off.apply(o, arguments);
};
$.publish = function() {
o.trigger.apply(o, arguments);
};
// Event Handlers
$.hashHandler = function(){ $.publish("urlChange", $.parseHash(window.location.hash.substr(1))); };
$.redirectHandler = function(event, url){ window.location.hash = $.genHash(url); };
// redirections manager
$.redirect = function(url){ $.publish('redirect', url); };
$.subscribe('redirect', $.redirectHandler)
$(window).bind('hashchange', $.hashHandler);
$(window).bind('load', $.hashHandler);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment