Permalink
Browse files

mass edit tag no work (some refactor may be needed)

  • Loading branch information...
1 parent 567bc64 commit 5fb0d7b52b89341e139574d92286726b2506cf48 t8g committed Jan 2, 2012
Showing with 64 additions and 18 deletions.
  1. +7 −5 app.js
  2. +5 −3 models.js
  3. +30 −2 public/js/main.js
  4. +22 −8 views/index.html
View
12 app.js
@@ -300,6 +300,7 @@ app.get('/documents/batch/download/:zipfile', function(req, res, next) {
res,
next
);
+ // supprimer le zip une fois télécharger ou régulièrement ?
});
/**
@@ -318,15 +319,16 @@ app.post('/documents/batch/tags', function(req, res) {
async.forEach(
docs,
- function(doc) {
+ function(doc, fn) {
var tags = doc.tags;
- tags = _.difference(tags, req.params.todelete);
- tags = _.union(tags, req.params.toadd);
+ tags = _.difference(tags, req.body.todelete);
+ tags = _.union(tags, req.body.toadd);
doc.tags = tags;
- doc.save();
+ doc.save(fn);
},
function(err) {
- res.respond(err || {}, err ? 500 : 200);
+ console.log('fin');
+ return res.respond(err || {}, err ? 500 : 200);
}
);
});
View
@@ -245,16 +245,18 @@ function define(mongoose, fn) {
Document.prototype.save = function(fn) {
var self = this;
self._save(function(err) {
- if (!err) fn(err);
- else if (err.message.indexOf('E11000') == 0) { // Sans doute prévoir un meilleur test (quid si autre champ unique ?)
+ if (!err) {
+ if (fn) fn(err);
+ } else if (err.message.indexOf('E11000') == 0) { // Sans doute prévoir un meilleur test (quid si autre champ unique ?)
// calcul du nouveau slug
var slug = self.slug.split('-');
var i = (slug.length > 1) ? slug.pop() : 0;
self.setValue('slug', slug.join('-') + '-' + (i*1+1));
self.isNew = true;
self.save(fn);
} else {
- throw new Error(err.message)
+ //throw new Error(err.message)
+ fn(err);
}
});
};
View
@@ -8,6 +8,19 @@ $(function($){
, $masterCheckbox = $documents.find('thead input')
, $documentCheckboxes = $documents.find('tbody input');
+ // close button on overlays
+ $('button.hide').click(function(ev) {
+ ev.preventDefault();
+ $(this).parents('.overlay').hide();
+ });
+
+ $('#documents tbody a').live('click', function(ev) {
+ ev.preventDefault();
+ $.get(this.href, function(data) {
+ $('.document_edit').show();
+ $('.document_edit .content').text(JSON.stringify(data));
+ });
+ });
/********/
/* Tags */
@@ -104,6 +117,21 @@ $(function($){
});
+ $('#save_global_tags').click(function(ev) {
+ ev.preventDefault();
+ var overlay = $(this).parents('.overlay');
+ $.post('/documents/batch/tags', {
+ ids: [].map.call($documentCheckboxes.filter(':checked'), function(el, i) {
+ return el.value;
+ }),
+ toadd: $globalTags.data('toadd'),
+ todelete: $globalTags.data('todelete')
+ }, function(data) {
+ console.log(data);
+ overlay.hide();
+ });
+ });
+
/************/
/* Uploader */
/************/
@@ -245,10 +273,10 @@ $(function($){
switch (action) {
case 'download':
$('.global_download').show();
- $('.global_download').html('MESSAGE ATTENTE ... + GIF ANIME OU ... ');
+ $('.global_download .content').html('MESSAGE ATTENTE ... + GIF ANIME OU ... ');
$.post(url, { ids: ids }, function(data) {
if (data.zipfile) {
- $('.global_download').html('<a href="' + '/documents/batch/download/' + data.zipfile + '">' + data.zipfile + '</a>');
+ $('.global_download .content').html('<a href="' + '/documents/batch/download/' + data.zipfile + '">' + data.zipfile + '</a>');
} else {
$('.global_download').hide();
alert('Error while creating archive file');
View
@@ -133,12 +133,18 @@
top: 6px;
right: 6px;
}
+
+ .overlay > div.content {
+ position: relative;
+ margin: 20px;
+ color: #fff;
+ }
</style>
<section id="rightbar" class="grid_8">
<section class="overlay global_uploads">
<h3>Uploads en cours</h3>
<div class="right">
- <button class="btn danger">Fermer</button>
+ <button class="btn danger hide">Fermer</button>
<button class="btn primary" onclick="alert('@TODO')">Édition par lots</button>
</div>
<ul>
@@ -148,22 +154,30 @@
<section class="overlay global_tags">
<h3>Edition des tags</h3>
<div class="right">
- <button class="btn danger">Fermer</button>
+ <button class="btn danger hide">Fermer</button>
</div>
- <div style="position:relative;margin:20px;">
+ <div class="content">
<ul id="global_tags">
</ul>
- <button class="btn">Enregistrer</button>
+ <button class="btn" id="save_global_tags">Enregistrer</button>
</div>
</section>
<section class="overlay global_download">
<h3>Téléchargement archive</h3>
<div class="right">
- <button class="btn danger">Fermer</button>
+ <button class="btn danger hide">Fermer</button>
</div>
- <div style="position:relative;margin:20px;">
- kjhkjhkjhkjh
+ <div class="content">
+ </div>
+ </section>
+
+ <section class="overlay document_edit">
+ <h3>Document</h3>
+ <div class="right">
+ <button class="btn danger hide">Fermer</button>
+ </div>
+ <div class="content">
</div>
</section>
@@ -192,9 +206,9 @@
<form action="/documents/batch/" style="text-align:right; opacity: 0;">
Pour la sélection :
<select>
- <option value="download">Télécharger archive
<option value="tags">Editer les tags
<option value="move">Déplacer
+ <option value="download">Télécharger archive
<option value="delete">Supprimer
</select>
<button class="btn">ok</button>

0 comments on commit 5fb0d7b

Please sign in to comment.