Permalink
Browse files

Merge pull request #6 from TheHippo/master

Update jade templates, actions now work in all views, delete feature
  • Loading branch information...
2 parents fc5affe + fe3cb83 commit 98f1604be6ae4e83fd830b212c91e1b8f2e153ef @masylum masylum committed Jul 5, 2011
View
3 Readme.md
@@ -61,8 +61,9 @@ First edit a configuration file like this:
locales: ['en', 'es'],
store: {
mongodb: {
- collection: 'my_translations
+ collection: 'my_translations'
}
+ }
}
}
View
3 lib/controllers/app.js
@@ -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) {
@@ -39,6 +39,7 @@ module.exports = function (DIALECT_HTTP) {
stats: stats,
locale: null
});
+ coll.drop();
});
});
} else {
View
25 lib/controllers/translate.js
@@ -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});
@@ -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 {
@@ -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');
+ }
+ });
};
View
4 lib/dialect_http.js
@@ -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());
@@ -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'));
View
6 lib/public/css/global.css
@@ -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;
@@ -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;
}
View
BIN 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.
View
54 lib/public/js/global.js
@@ -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 () {
@@ -177,4 +224,11 @@ $(function () {
approve($textarea, false);
return false;
});
+
+ $("a.delete").click(function() {
+ var $textarea = getTextarea($(this));
+ deleteTranslation($textarea, false);
+ return false;
+
+ });
});
View
6 lib/views/dashboard.jade
@@ -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
View
20 lib/views/layout.jade
@@ -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
@@ -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
View
38 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;
@@ -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
View
14 lib/views/public.jade
@@ -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
@@ -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
View
12 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.