Skip to content

Commit

Permalink
Merge pull request masylum#6 from TheHippo/master
Browse files Browse the repository at this point in the history
Update jade templates, actions now work in all views, delete feature
  • Loading branch information
masylum committed Jul 5, 2011
2 parents fc5affe + fe3cb83 commit 98f1604
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 50 deletions.
3 changes: 2 additions & 1 deletion Readme.md
Expand Up @@ -61,8 +61,9 @@ First edit a configuration file like this:
locales: ['en', 'es'],
store: {
mongodb: {
collection: 'my_translations
collection: 'my_translations'
}
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/controllers/app.js
Expand Up @@ -26,7 +26,7 @@ module.exports = function (DIALECT_HTTP) {
return res;
}

DIALECT_HTTP.dialect.store.collection.mapReduce(map, reduce, function (err, coll) {
DIALECT_HTTP.dialect.store.collection.mapReduce(map.toString(), reduce.toString(),{out:"summary"}, function (err, coll) {
if (coll) {
coll.find({}, function (err, cursor) {
cursor.toArray(function (err, docs) {
Expand All @@ -39,6 +39,7 @@ module.exports = function (DIALECT_HTTP) {
stats: stats,
locale: null
});
coll.drop();
});
});
} else {
Expand Down
25 changes: 23 additions & 2 deletions lib/controllers/translate.js
Expand Up @@ -77,7 +77,10 @@ module.exports = function (DIALECT_HTTP) {
cursor.toArray(funk.result('translations'));
}
);
dialect.store.count(query, funk.result('count'));
dialect.store.count({locale: locale}, funk.result('count'));
dialect.store.count({locale: locale, translation: {'$ne': null}, approved: true}, funk.result('count_ok'));
dialect.store.count({locale: locale, translation: {'$ne': null}, approved: false}, funk.result('count_pending'));
dialect.store.count({locale: locale, translation: null}, funk.result('count_missing'));

funk.parallel(function () {
var paginator = require('paginate-js')({elements_per_page: results_per_page, count_elements: this.count});
Expand All @@ -89,7 +92,10 @@ module.exports = function (DIALECT_HTTP) {
paginator: paginator.render({url: '/' + req.param('locale') + '/' + el + '/%N', page: req.param('page')}),
page: req.param('page'),
category: el,
locale: req.param('locale')
locale: req.param('locale'),
count_pending: this.count_pending,
count_missing: this.count_missing,
count_ok: this.count_ok
});
});
} else {
Expand Down Expand Up @@ -133,5 +139,20 @@ module.exports = function (DIALECT_HTTP) {
res.end('you are not authorized to perform that operation');
}
});

app.post("/:locale/delete", authenticate, function (req, res) {
if (app.dynamicViewHelpers.can_approve(req, res)) {
dialect.store.collection.remove(
{_id: ObjectID.createFromHexString(req.param('id'))},
function () {
res.writeHead(200);
res.end('ok');
}
);
} else {
res.writeHead(403);
res.end('you are not authorized to perform that operation');
}
});

};
4 changes: 3 additions & 1 deletion lib/dialect_http.js
Expand Up @@ -72,6 +72,8 @@ DIALECT_HTTP.run = function () {
var app = DIALECT_HTTP.app,
options = DIALECT_HTTP.options,
dialect = DIALECT_HTTP.dialect = require('dialect').dialect(options.dialect);

//console.log(options.dialect);

app.configure(function () {
app.use(express.favicon());
Expand All @@ -83,7 +85,7 @@ DIALECT_HTTP.run = function () {
app.use(express.session({
cookie: options.session.cookie,
secret: options.session.secret,
store: require('connect-mongodb')(options.sessions_db)
store: require('connect-mongo')(options.sessions_db)
}));

app.use(express['static'](_lib_path + '/public'));
Expand Down
6 changes: 5 additions & 1 deletion lib/public/css/global.css
Expand Up @@ -152,7 +152,7 @@ form {
float:left;
border: 1px solid #bbb;
width: 938px;
height: 94px;
height: 110px;
-moz-box-shadow: inset 1px 1px 0px #fff;
-webkit-box-shadow:inset 1px 1px 0px #fff;
box-shadow: inset 1px 1px 0px #fff;
Expand Down Expand Up @@ -294,6 +294,10 @@ form .options a.autotranslate span {
}

form .options a.clean span {
background:url("/images/left.png") no-repeat scroll 0 50% transparent;
}

form .options a.delete span {
background:url("/images/trash.png") no-repeat scroll 0 50% transparent;
}

Expand Down
Binary file added lib/public/images/left.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions lib/public/js/global.js
Expand Up @@ -105,6 +105,53 @@ $(function () {
updateBars($text_bar, total, ok, pending, missing);
updateLastStatus($textarea);
};

deleteTranslation = function ($textarea, approve) {
var $form = $textarea.parent(),
$text_bar = $('h1.bars'),
parts = $text_bar.text().match(/[0-9]+/g),
ok, pending, missing, total;

total = parts[0];
ok = parts[1];
pending = parts[2];
missing = parts[3];

$.ajax({
type: 'POST',
url: '/' + current_locale + '/delete/',
data: {
id: $textarea.prevAll('input').val()
},
success: function () {
$textarea.busy('hide');
$form.remove();
},
dataType: 'text'
});

$textarea.busy({title: 'saving...'});

total--;
classes = $form.attr('class').split(' ');
for (var i = 0; i<classes.length; i++) {
if (classes[i] == "ok") {
ok--;
break;
}
if (classes[i] == "pending") {
pending--;
break;
}
if (classes[i] == "missing") {
missing--;
break;
}
}

updateBars($text_bar, total, ok, pending, missing);
updateLastStatus($textarea);
};

$('textarea.translation')
.each(function () {
Expand Down Expand Up @@ -177,4 +224,11 @@ $(function () {
approve($textarea, false);
return false;
});

$("a.delete").click(function() {
var $textarea = getTextarea($(this));
deleteTranslation($textarea, false);
return false;

});
});
6 changes: 3 additions & 3 deletions lib/views/dashboard.jade
Expand Up @@ -17,7 +17,7 @@ h1 Dashboard
= stat.pending + ' pending, '
= count - stat.ok - stat.pending + ' missing'
div.bars
a.ok(href: '/' + locale + '/ok/', style: 'width:' + percent_ok + '%;') &nbsp
a.pending(href: '/' + locale + '/missing/', style: 'width:' + percent_pending + '%;') &nbsp
a.missing(href: '/' + locale + '/pending/', style: 'width:' + percent_missing + '%;') &nbsp
a.ok(href= '/' + locale + '/ok/', style= 'width:' + percent_ok + '%;') &nbsp
a.pending(href= '/' + locale + '/pending/', style= 'width:' + percent_pending + '%;') &nbsp
a.missing(href= '/' + locale + '/missing/', style= 'width:' + percent_missing + '%;') &nbsp
.clearer
20 changes: 10 additions & 10 deletions lib/views/layout.jade
Expand Up @@ -2,22 +2,22 @@
html
head
title= title || ''
link(rel: 'stylesheet', href: '/css/reset.css' )
link(rel: 'stylesheet', href: '/css/global.css' )
script(src: 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js')
script(src: '/js/loading.js')
script(src: '/js/translate.js')
script(src: '/js/global.js')
link(rel= 'stylesheet', href= '/css/reset.css' )
link(rel= 'stylesheet', href= '/css/global.css' )
script(src= 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js')
script(src= '/js/loading.js')
script(src= '/js/translate.js')
script(src= '/js/global.js')
body
nav#header
.wrapper
a#logo(href: '/')= options.title || 'dialect'
a#logout(href: '/auth/logout') logout
a#logo(href= '/')= options.title || 'dialect'
a#logout(href= '/auth/logout') logout
ul#locales
-each loc in authorized_locales
-if (loc !== dialect.config('base_locale'))
li
a(href: '/' + loc + '/all/', class: loc === locale ? 'selected' : '')
a(href= '/' + loc + '/all/', class= loc === locale ? 'selected' : '')
= loc
.clearer

Expand All @@ -28,7 +28,7 @@ html
-if (Object.keys(messages).length)
#flash_messages
-each msgs, type in messages
div(class: 'box ' + type)
div(class= 'box ' + type)
h2= type
ul
-each msg in msgs
Expand Down
38 changes: 20 additions & 18 deletions lib/views/locale.jade
@@ -1,12 +1,12 @@
input(type: 'hidden', name: 'current_locale', value: locale, id: 'current_locale')
input(type: 'hidden', name: 'base_locale', value: dialect.config('base_locale'), id: 'base_locale')
input(type= 'hidden', name= 'current_locale', value= locale, id= 'current_locale')
input(type= 'hidden', name= 'base_locale', value= dialect.config('base_locale'), id= 'base_locale')

-if (category !== 'All')
h1#breadcrumbs
a(href: '/' + locale + '/all/') All
a(href= '/' + locale + '/all/') All
| &raquo;
= category
-else if (locale !== dialect.config('base_locale'))
- if (locale !== dialect.config('base_locale'))
-// TODO: Move this crap
-var percent_ok = count ? (count_ok / count) * 100 : 0;
-var percent_pending = count ? (count_pending / count) * 100 : 0;
Expand All @@ -15,38 +15,40 @@ input(type: 'hidden', name: 'base_locale', value: dialect.config('base_locale'),
h1.bars
= count + ' strings, '
= count_ok + ' '
a.ok(href: '/' + locale + '/ok/') ok
a.ok(href= '/' + locale + '/ok/') ok
= ', ' + count_pending + ' '
a.pending(href: '/' + locale + '/pending/') pending
a.pending(href= '/' + locale + '/pending/') pending
= ', ' + (count - count_ok - count_pending) + ' '
a.missing(href: '/' + locale + '/missing/') missing
a.missing(href= '/' + locale + '/missing/') missing
div.bars
a.ok(href: '/' + locale + '/ok/', style: 'width:' + percent_ok + '%;') &nbsp
a.pending(href: '/' + locale + '/pending/', style: 'width:' + percent_pending + '%;') &nbsp
a.missing(href: '/' + locale + '/missing/', style: 'width:' + percent_missing + '%;') &nbsp
a.ok(href= '/' + locale + '/ok/', style= 'width:' + percent_ok + '%;') &nbsp
a.pending(href= '/' + locale + '/pending/', style= 'width:' + percent_pending + '%;') &nbsp
a.missing(href= '/' + locale + '/missing/', style= 'width:' + percent_missing + '%;') &nbsp
.clearer

.clearer

-each translation in translations
-var stat = translation.translation ? (translation.approved ? 'ok' : 'pending') : 'missing';
form(action: '/' + locale + '/translate/', method: 'POST', class: stat + (can_approve ? ' can_approve' : ''), autocomplete: 'off')
input(type: 'hidden', name: 'id', value: translation._id)
form(action= '/' + locale + '/translate/', method= 'POST', class= stat + (can_approve ? ' can_approve' : ''), autocomplete= 'off')
input(type= 'hidden', name= 'id', value= translation._id)
.original
= translation.original
textarea.translation(name: 'translation')= translation.translation || ''
textarea.translation(name= 'translation')= translation.translation || ''

.options
a.get_original(href: '#')
a.get_original(href= '#')
span get original
a.autotranslate(href: '#')
a.autotranslate(href= '#')
span autotranslate
a.clean(href: '#')
a.clean(href= '#')
span clean
a.reject(href: '#')
a.reject(href= '#')
span reject
a.approve(href: '#')
a.approve(href= '#')
span approve
a.delete(href="#")
span delete
.meta
-if (translation.context)
span.context
Expand Down
14 changes: 7 additions & 7 deletions lib/views/public.jade
Expand Up @@ -2,12 +2,12 @@
html
head
title= title || ''
link(rel: 'stylesheet', href: '/css/reset.css' )
link(rel: 'stylesheet', href: '/css/global.css' )
script(src: 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js')
script(src: '/js/loading.js')
script(src: '/js/translate.js')
script(src: '/js/global.js')
link(rel= 'stylesheet', href= '/css/reset.css' )
link(rel= 'stylesheet', href= '/css/global.css' )
script(src= 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js')
script(src= '/js/loading.js')
script(src= '/js/translate.js')
script(src= '/js/global.js')
body
nav#header
.wrapper
Expand All @@ -21,7 +21,7 @@ html
-if (Object.keys(messages).length)
#flash_messages
-each msgs, type in messages
div(class: 'box ' + type)
div(class= 'box ' + type)
h2= type
ul
-each msg in msgs
Expand Down
12 changes: 6 additions & 6 deletions lib/views/public/users/login.jade
@@ -1,12 +1,12 @@
form(action: '/auth/form/', method: 'post', style: 'width: 160px;margin: 0 auto;height:auto;')
form(action= '/auth/form/', method= 'post', style= 'width= 160px;margin= 0 auto;height=auto;')
fieldset
.field
label(for: 'username') Email
input(id: 'username', name: 'username', value: '', type: 'text')
label(for= 'username') Email
input(id= 'username', name= 'username', value= '', type= 'text')

.field
label(for: 'password') Password
input(id: 'password', name: 'password', value: '', type: 'password')
label(for= 'password') Password
input(id= 'password', name= 'password', value= '', type= 'password')

.operations
input.button(type: 'submit', value: 'Login')
input.button(type= 'submit', value= 'Login')

0 comments on commit 98f1604

Please sign in to comment.