Permalink
Browse files

implements domain preview mode via ajax calls and refactores domain m…

…odel
  • Loading branch information...
MSchmidt committed Jun 3, 2010
1 parent 1c377a7 commit 77755f962915def346a9c88633940f486523d9fe
@@ -102,7 +102,11 @@ def update
# DELETE /domains/1.xml
# ADMIN only
def destroy
@domain = Domain.find(params[:id])
if is_admin?
@domain = Domain.find(params[:id])
else
@domain = current_user.domains.find(params[:id])
end
@domain.send_later(:destroy_config)
flash[:notice] = 'Domain was successfully destroyed.'
@@ -111,4 +115,20 @@ def destroy
format.xml { head :ok }
end
end
def change_preview
if is_admin?
domain = Domain.find(params[:id])
else
domain = current_user.domains.find(params[:id])
end
domain.mount_point = params[:domain_path]
vhost = { :vhost => domain.generate_vhost.gsub!(/\n/, '<br />') }
respond_to do |format|
format.html { redirect_to(user_root_url) }
format.js { render :json => vhost }
format.xml { render :xml => vhost }
end
end
end
View
@@ -10,7 +10,7 @@ def perform
write_config
end
def write_config
def generate_vhost
servername = self.fqdn
serveralias = "www." + servername
email = self.user.email
@@ -19,24 +19,35 @@ def write_config
rails = self.rails
vhost_template = ERB.new(read_template('apache2_vhost.conf')).result(binding)
end
def generate_default_index
servername = self.fqdn
php = self.php
index_template = ERB.new(read_template('index.html')).result(binding)
end
def write_config
vhost_template = generate_vhost
index_template = generate_default_index
path = File.join(self.user.userpath, self.mount_point)
File.open(File.join(VHOST_TARGET_DIR,VHOST_PREFIX + servername), "w") do |f|
File.open(File.join(VHOST_TARGET_DIR, VHOST_PREFIX + self.fqdn), "w") do |f|
f.write(vhost_template)
end
Dir.mkdir(path) unless File.exists?(path)
indexfile = File.join(path, "index.html")
indexfile = File.join(path, "index.php") if php
indexfile = self.php ? File.join(path, "index.php") : File.join(path, "index.html")
unless File.exists?(indexfile)
File.open(indexfile, "w") do |f|
f.write(index_template)
end
end
system("a2ensite #{VHOST_PREFIX+servername}")
system("a2ensite " + VHOST_PREFIX + self.fqdn)
system("/etc/init.d/apache2 reload")
rescue Errno::ENOENT
View
@@ -1,5 +1,11 @@
<html>
<body><h1>It works!</h1>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title><%= servername %> is online!</title>
</head>
<body>
<h1>It works!</h1>
<p><%= servername %> is online!</p>
<p>&nbsp;</p>
@@ -15,6 +15,7 @@
= link_to 'Destroy', domain, :confirm => 'Are you sure?', :method => :delete
%span.domain_path= h(domain.mount_point)
= link_to '✎', '#edit', :class => 'domain_edit'
%span.domain_id.hidden= domain.id
%span.domain_owner.hidden= domain.user_id
%br/
@@ -30,4 +30,10 @@
= yield
#infobar
= "#{@unsaved_domains_count} domains got changed. See what GCCP will do."
#infobar-content
#infobar-collapsed
= "Some domains got changed. See what GCCP will do."
#infobar-expanded
#infobar-buttons
%button#undo_button Undo
%button#save_button Save
View
@@ -1,7 +1,8 @@
ActionController::Routing::Routes.draw do |map|
map.resources :users, :member => { :folder_structure => :get }
map.resources :domains, :databases
map.resources :domains, :member => { :change_preview => :get }
map.resources :databases
map.resource :user, :only => {}, :collection => {:change_password => :get, :update_password => :put, :update_db_password => :put}
map.admin 'admin', :controller => 'admin', :action => 'index'
@@ -16,15 +16,19 @@ function generate_password(pwlength) {
window.addEvent('domready', function(){
var infobar_fx = new Fx.Tween($('infobar'), {
property: 'height',
link: 'cancel'
link: 'cancel',
onComplete: function(){
//$('infobar-collapsed').fade('toggle');
//$('infobar-expanded').fade('toggle');
}
});
var infobar_original_height = $('infobar').getStyle('height');
//var infobar_original_content = $('infobar').get();
console.log(infobar_original_height);
$('infobar').addEvent('click', function(e){
if (this.getStyle('height') == infobar_original_height) {
infobar_fx.start(100);
infobar_fx.start(250);
} else {
infobar_fx.start(infobar_original_height);
}
@@ -1,21 +1,15 @@
window.addEvent('domready', function(){
$$('.domain').each(function(i){
i.store('pos_x', i.getStyle('left'));
i.store('pos_y', i.getStyle('top'));
i.store('domain_path', i.getElement('.domain_path').get('html'));
var myDrag = new Drag.Move(i, {
handle: i.getElement('.domain-nob'),
container: 'workbench',
onDrop: function(element, droppable, event){
if (!droppable) console.log(element, ' dropped on nothing');
else console.log(element, 'dropped on', droppable, 'event', event);
$('infobar').fade('hide').fade('in');
},
onEnter: function(element, droppable){
console.log(element, 'entered', droppable);
},
onLeave: function(element, droppable){
console.log(element, 'left', droppable);
}
});
@@ -33,26 +27,44 @@ window.addEvent('domready', function(){
});
});
$('undo_button').addEvent('click', function(event){
$$('.domain').each(function(i){
var move = new Fx.Morph(i);
move.start({
'left': i.retrieve('pos_x'),
'top': i.retrieve('pos_y')
});
i.getElement('.domain_path').set('html', i.retrieve('domain_path'));
});
event.stop();
});
$('save_button').addEvent('click', function(event){
// do all the saving action here
event.stop();
});
//open_preferences($('domain1'));
function open_preferences(parent_element) {
if (parent_element.getElement('.settings-bubble') == null) {
var settings_bubble = $('settings_bubble_blueprint').clone().removeClass('hidden');
settings_bubble.fade('hide').inject(parent_element).fade('in');
var jsonRequest = new Request({
var request = new Request({
url: "/users/" + parent_element.getElement('.domain_owner').get('html') + "/folder_structure.xml",
onSuccess: function(response){
var fibro = new MooFibro(parent_element.getElement('span.domain_path'), {
container: settings_bubble.getElement('.browser'),
tree: response,
//preselected: 'more/eeven_more/really_deep',
animate: true,
onSelect: function(selected){
console.log('select: ' + selected);
this.target.highlight();
change_domain_path(parent_element, selected)
},
onExtend: function(extended, path, direction){
console.log('extend: ' + extended + ' - ' + path + ' | ' + direction);
//console.log('extend: ' + extended + ' - ' + path + ' | ' + direction);
}
});
}
@@ -61,4 +73,15 @@ window.addEvent('domready', function(){
parent_element.getElement('.settings-bubble').fade('toggle');
}
}
function change_domain_path(element, new_path){
var request = new Request.JSON({
url: "/domains/" + element.getElement('.domain_id').get('html') + "/change_preview.js",
onSuccess: function(response){
$('infobar-expanded').set('html', response.vhost);
}
}).get({
'domain_path': new_path
});
}
});
@@ -42,13 +42,22 @@ body {
background-color: white; }
#infobar {
visibility: hidden;
#visibility: hidden;
position: fixed;
bottom: 0;
width: 100%;
height: 30px;
color: white;
background-color: black; }
background-color: black;
z-index: 100; }
#infobar #infobar-content {
padding: 5px 10px; }
#infobar #infobar-content #infobar-expanded {
display: none;
height: 250px;
overflow: auto; }
#infobar #infobar-content #infobar-buttons {
float: right;
text-align: right; }
.big {
font-size: 1.5em; }
@@ -45,13 +45,22 @@ $nav_li_width: 120px
background-color: #fff
#infobar
visibility: hidden
#visibility: hidden
position: fixed
bottom: 0
width: 100%
height: 30px
color: #fff
background-color: #000
z-index: 100
#infobar-content
padding: 5px 10px
#infobar-expanded
display: none
height: 250px
overflow: auto
#infobar-buttons
float: right
text-align: right
.big
font-size: 1.5em

0 comments on commit 77755f9

Please sign in to comment.