factor out Metamaps.Admin

This commit is contained in:
Devin Howard 2016-04-13 16:04:15 +08:00
parent 799f6e4623
commit be99ad8285
3 changed files with 55 additions and 54 deletions

View file

@ -25,6 +25,7 @@
//= require ./src/views/room
//= require ./src/JIT
//= require ./src/Metamaps
//= require ./src/Metamaps.Admin
//= require ./src/Metamaps.Import
//= require ./src/Metamaps.JIT
//= require_directory ./shims

View file

@ -0,0 +1,54 @@
/* global Metamaps, $ */
/*
* Metamaps.Admin.js.erb
*
* Dependencies: none!
*/
Metamaps.Admin = {
selectMetacodes: [],
allMetacodes: [],
init: function () {
var self = Metamaps.Admin
$('#metacodes_value').val(self.selectMetacodes.toString())
},
selectAll: function () {
var self = Metamaps.Admin
$('.editMetacodes li').removeClass('toggledOff')
self.selectMetacodes = self.allMetacodes.slice(0)
$('#metacodes_value').val(self.selectMetacodes.toString())
},
deselectAll: function () {
var self = Metamaps.Admin
$('.editMetacodes li').addClass('toggledOff')
self.selectMetacodes = []
$('#metacodes_value').val(0)
},
liClickHandler: function () {
var self = Metamaps.Admin
if ($(this).attr('class') != 'toggledOff') {
$(this).addClass('toggledOff')
var value_to_remove = $(this).attr('id')
self.selectMetacodes.splice(self.selectMetacodes.indexOf(value_to_remove), 1)
$('#metacodes_value').val(self.selectMetacodes.toString())
}
else if ($(this).attr('class') == 'toggledOff') {
$(this).removeClass('toggledOff')
self.selectMetacodes.push($(this).attr('id'))
$('#metacodes_value').val(self.selectMetacodes.toString())
}
},
validate: function () {
var self = Metamaps.Admin
if (self.selectMetacodes.length == 0) {
alert('Would you pretty please select at least one metacode for the set?')
return false
}
}
}

View file

@ -5516,57 +5516,3 @@ Metamaps.Mapper = {
});
}
}; // end Metamaps.Mapper
/*
*
* ADMIN
*
*/
Metamaps.Admin = {
selectMetacodes: [],
allMetacodes: [],
init: function () {
var self = Metamaps.Admin;
$('#metacodes_value').val(self.selectMetacodes.toString());
},
selectAll: function () {
var self = Metamaps.Admin;
$('.editMetacodes li').removeClass('toggledOff');
self.selectMetacodes = self.allMetacodes.slice(0);
$('#metacodes_value').val(self.selectMetacodes.toString());
},
deselectAll: function () {
var self = Metamaps.Admin;
$('.editMetacodes li').addClass('toggledOff');
self.selectMetacodes = [];
$('#metacodes_value').val(0);
},
liClickHandler: function () {
var self = Metamaps.Admin;
if ($(this).attr('class') != 'toggledOff') {
$(this).addClass('toggledOff');
var value_to_remove = $(this).attr('id');
self.selectMetacodes.splice(self.selectMetacodes.indexOf(value_to_remove), 1);
$('#metacodes_value').val(self.selectMetacodes.toString());
}
else if ($(this).attr('class') == 'toggledOff') {
$(this).removeClass('toggledOff');
self.selectMetacodes.push($(this).attr('id'));
$('#metacodes_value').val(self.selectMetacodes.toString());
}
},
validate: function () {
var self = Metamaps.Admin;
if (self.selectMetacodes.length == 0) {
alert('Would you pretty please select at least one metacode for the set?');
return false;
}
}
};