Skip to content

Commit

Permalink
edit existing routine support
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Aug 10, 2015
1 parent 662f8f6 commit 62e4305
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
35 changes: 22 additions & 13 deletions edit.js
Expand Up @@ -12,21 +12,30 @@ aside.input = {
}

function editmode() {
// create a new figure in the syllabus
var routine = document.getElementById('routine');

var name = document.getElementById('stepname').value;
name = name || 'New Figure';
newFigure = {figure: '-', name: name, steps: []};
syllabus[dance].figures.push(newFigure);
var listitems = routine.querySelectorAll('li')

// add it to the routine
var routine = document.getElementById('routine');
var index = syllabus[dance].figures.length - 1;
var li = document.createElement('li');
li.setAttribute('data-index', index);
var span = document.createElement('span');
span.textContent = syllabus[dance].figures[index].name;
li.appendChild(span);
routine.appendChild(li);
if (!name && listitems.length == 1) {
// edit existing figure
var index = listitems[0].getAttribute('data-index');
newFigure = syllabus[dance].figures[index];
} else {
// create a new figure in the syllabus
name = name || 'New Figure';
newFigure = {figure: '-', name: name, steps: []};
syllabus[dance].figures.push(newFigure);

// add it to the routine
var index = syllabus[dance].figures.length - 1;
var li = document.createElement('li');
li.setAttribute('data-index', index);
var span = document.createElement('span');
span.textContent = syllabus[dance].figures[index].name;
li.appendChild(span);
routine.appendChild(li);
}

// display count
aside.count.textContent = 'count: ' + (count = 0);
Expand Down
3 changes: 3 additions & 0 deletions pick.js
Expand Up @@ -104,6 +104,9 @@ function displayMenu() {
figures[index].steps = steps;
});
}

// clear stepname
document.getElementById('stepname').value = '';
});
} else {
// mark row as unavailable
Expand Down
11 changes: 5 additions & 6 deletions post.cgi
Expand Up @@ -20,10 +20,10 @@ process.stdin.on('end', function() {
if (!request.dance || !request.figure || !request.steps) return;

// write out figure
var fileName = 'data/' + toFileName(request.dance) + '/' +
toFileName(request.figure) + '.json';
if (fs.existsSync(fileName)) fs.unlinkSync(fileName);
fs.writeFileSync(fileName, JSON.stringify(request.steps, null, 2) + "\n");
var fileName = toFileName(request.figure) + '.json';
var fullName = 'data/' + toFileName(request.dance) + '/' + fileName;
if (fs.existsSync(fullName)) fs.unlinkSync(fullName);
fs.writeFileSync(fullName, JSON.stringify(request.steps, null, 2) + "\n");

// update index
var indexName = 'data/' + toFileName(request.dance) + '/index.json';
Expand All @@ -35,8 +35,7 @@ process.stdin.on('end', function() {
}
}
if (i >= index.figures.length) {
index.figures.push({name: request.figure,
file: toFileName(request.figure) + '.json'});
index.figures.push({name: request.figure, file: fileName});
}

// write out index
Expand Down

0 comments on commit 62e4305

Please sign in to comment.