Large set of changes - building the GUI for the data tracking app.

This commit is contained in:
Wynne Crisman
2016-08-17 17:54:59 -07:00
parent 08266cdd41
commit b3bbdc0c2a
47 changed files with 4186 additions and 158 deletions

View File

@@ -182,7 +182,7 @@ module.exports = function(app, rootPath, passport, smtpTransport, sequelize) {
}); });
}); });
app.get('/admin/user-data', isLoggedIn, function(req, res) { app.get('/admin/user/list', isLoggedIn, function(req, res) {
try { try {
if(req.user.admin) { if(req.user.admin) {
sequelize.models.User.findAll().then(function(values) { sequelize.models.User.findAll().then(function(values) {
@@ -190,15 +190,450 @@ module.exports = function(app, rootPath, passport, smtpTransport, sequelize) {
}); });
} }
else { else {
//TODO: Return some kind of error.
res.status(400).end();
} }
} }
catch(e) {console.log(e);} catch(e) {console.log(e);}
}); });
app.post('/admin/createUser', isLoggedIn, function(req, res) { app.post('/admin/user/create', isLoggedIn, function(req, res) {
try { try {
res.json({status: 'success'}); if(req.user.admin) {
var login = req.body.login;
var password = req.body.password;
sequelize.models.User.create({
login: login,
password: sequelize.models.User.generateHash(password),
admin: true
}).then(function(user) {
res.json({result: 'success'});
}).catch(function(err) {
console.log(err);
res.json({result: 'duplicate'});
});
}
} catch(e) {console.log(e);}
});
app.post('/admin/user/delete', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var userId = req.body.id;
/* This isn't quite right.. the return of user.destroy() causes problems if the user is not found. Regardless, it is cleaner code to user the class method to destroy the instance rather than load it just to destroy it.
sequelize.models.User.findById(userId, {}).then(function(user) {
if(user) {
return user.destroy();
}
else {
res.json({result: 'failure'});
}
}).then(function() {
res.json({result: 'success'});
}).catch(function(err) {
console.log(err);
res.json({result: 'failure'});
});
*/
sequelize.models.User.destroy({where: {id: userId}}).then(function(count) {
if(count == 1) {
res.json({result: 'success'});
}
else {
res.json({result: 'failure'});
}
}).catch(function(err) {
console.log(err);
res.json({result: 'failure'});
});
}
} catch(e) {console.log(e);}
});
app.post('/admin/user/changeLogin', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var userId = req.body.id;
var login = req.body.login;
sequelize.models.User.findById(userId, {}).then(function(user) {
user.login = login;
return user.save();
}).then(function() {
res.json({result: 'success'});
}).catch(function(err) {
console.log(err);
res.json({result: 'failure'});
});
}
} catch(e) {console.log(e);}
});
app.post('/admin/user/resetPassword', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var userId = req.body.id;
var password = req.body.password;
sequelize.models.User.findById(userId, {}).then(function(user) {
user.password = sequelize.models.User.generateHash(password);
return user.save();
}).then(function() {
res.json({result: 'success'});
}).catch(function(err) {
console.log(err);
res.json({result: 'failure'});
});
}
} catch(e) {console.log(e);}
});
app.get('/admin/venues/list', isLoggedIn, function(req, res) {
try {
var showDeleted = req.query.showDeleted == 'true';
sequelize.models.Venue.findAll({paranoid: !showDeleted}).then(function(values) {
res.json(values);
});
}
catch(e) {console.log(e);}
});
app.post('/admin/venues/create', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var name = req.body.name;
sequelize.models.Venue.create({
name: name
}).then(function(user) {
res.json({result: 'success'});
}).catch(function(err) {
console.log(err);
res.json({result: 'duplicate'});
});
}
} catch(e) {console.log(e);}
});
app.post('/admin/venues/delete', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var id = req.body.id;
sequelize.models.Venue.destroy({where: {id: id}}).then(function(count) {
if(count == 1) {
res.json({result: 'success'});
}
else {
res.json({result: 'failure'});
}
}).catch(function(err) {
console.log(err);
res.json({result: 'failure'});
});
}
} catch(e) {console.log(e);}
});
app.post('/admin/venues/edit', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var id = req.body.id;
var name = req.body.name;
sequelize.models.Venue.findById(id, {}).then(function(venue) {
venue.name = name;
return venue.save();
}).then(function() {
res.json({result: 'success'});
}).catch(function(err) {
console.log(err);
res.json({result: 'failure'});
});
}
} catch(e) {console.log(e);}
});
app.get('/admin/measures/list', isLoggedIn, function(req, res) {
try {
var showDeleted = req.query.showDeleted == 'true';
sequelize.models.Measure.findAll({paranoid: !showDeleted}).then(function(values) {
res.json(values);
});
}
catch(e) {console.log(e);}
});
app.post('/admin/measures/create', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var name = req.body.name;
var postfix = req.body.postfix;
sequelize.models.Measure.create({
name: name,
postfix: postfix
}).then(function(user) {
res.json({result: 'success'});
}).catch(function(err) {
console.log(err);
res.json({result: 'duplicate'});
});
}
} catch(e) {console.log(e);}
});
app.post('/admin/measures/delete', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var id = req.body.id;
sequelize.models.Measure.destroy({where: {id: id}}).then(function(count) {
if(count == 1) {
res.json({result: 'success'});
}
else {
res.json({result: 'failure'});
}
}).catch(function(err) {
console.log(err);
res.json({result: 'failure'});
});
}
} catch(e) {console.log(e);}
});
app.post('/admin/measures/edit', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var id = req.body.id;
var name = req.body.name;
var postfix = req.body.postfix;
sequelize.models.Measure.findById(id, {}).then(function(measure) {
measure.name = name;
measure.postfix = postfix;
return measure.save();
}).then(function() {
res.json({result: 'success'});
}).catch(function(err) {
console.log(err);
res.json({result: 'failure'});
});
}
} catch(e) {console.log(e);}
});
app.get('/admin/categories/list', isLoggedIn, function(req, res) {
try {
var showDeleted = req.query.showDeleted == 'true';
sequelize.models.Category.findAll({paranoid: !showDeleted}).then(function(values) {
res.json(values);
});
}
catch(e) {console.log(e);}
});
app.post('/admin/categories/create', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var name = req.body.name;
sequelize.models.Category.create({
name: name
}).then(function(user) {
res.json({result: 'success'});
}).catch(function(err) {
console.log(err);
res.json({result: 'duplicate'});
});
}
} catch(e) {console.log(e);}
});
app.post('/admin/categories/delete', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var id = req.body.id;
sequelize.models.Category.destroy({where: {id: id}}).then(function(count) {
if(count == 1) {
res.json({result: 'success'});
}
else {
res.json({result: 'failure'});
}
}).catch(function(err) {
console.log(err);
res.json({result: 'failure'});
});
}
} catch(e) {console.log(e);}
});
app.post('/admin/categories/edit', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var id = req.body.id;
var name = req.body.name;
sequelize.models.Category.findById(id, {}).then(function(category) {
category.name = name;
return category.save();
}).then(function() {
res.json({result: 'success'});
}).catch(function(err) {
console.log(err);
res.json({result: 'failure'});
});
}
} catch(e) {console.log(e);}
});
app.get('/admin/subcategories/list', isLoggedIn, function(req, res) {
try {
var showDeleted = req.query.showDeleted == 'true';
sequelize.models.Subcategory.findAll({paranoid: !showDeleted}).then(function(values) {
res.json(values);
});
}
catch(e) {console.log(e);}
});
app.post('/admin/subcategories/create', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var name = req.body.name;
sequelize.models.Subcategory.create({
name: name
}).then(function(user) {
res.json({result: 'success'});
}).catch(function(err) {
console.log(err);
res.json({result: 'duplicate'});
});
}
} catch(e) {console.log(e);}
});
app.post('/admin/subcategories/delete', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var id = req.body.id;
sequelize.models.Subcategory.destroy({where: {id: id}}).then(function(count) {
if(count == 1) {
res.json({result: 'success'});
}
else {
res.json({result: 'failure'});
}
}).catch(function(err) {
console.log(err);
res.json({result: 'failure'});
});
}
} catch(e) {console.log(e);}
});
app.post('/admin/subcategories/edit', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var id = req.body.id;
var name = req.body.name;
sequelize.models.Subcategory.findById(id, {}).then(function(subcategory) {
subcategory.name = name;
return subcategory.save();
}).then(function() {
res.json({result: 'success'});
}).catch(function(err) {
console.log(err);
res.json({result: 'failure'});
});
}
} catch(e) {console.log(e);}
});
app.get('/admin/items/list', isLoggedIn, function(req, res) {
try {
var showDeleted = req.query.showDeleted == 'true';
sequelize.models.Item.findAll({paranoid: !showDeleted}).then(function(values) {
res.json(values);
});
}
catch(e) {console.log(e);}
});
app.post('/admin/items/create', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var name = req.body.name;
var defaultPrice = req.body.defaultPrice;
var measures = req.body.measures;
sequelize.models.Item.create({
name: name,
defaultPrice: defaultPrice,
measures: measures
}).then(function(user) {
res.json({result: 'success'});
}).catch(function(err) {
console.log(err);
res.json({result: 'duplicate'});
});
}
} catch(e) {console.log(e);}
});
app.post('/admin/items/delete', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var id = req.body.id;
sequelize.models.Item.destroy({where: {id: id}}).then(function(count) {
if(count == 1) {
res.json({result: 'success'});
}
else {
res.json({result: 'failure'});
}
}).catch(function(err) {
console.log(err);
res.json({result: 'failure'});
});
}
} catch(e) {console.log(e);}
});
app.post('/admin/items/edit', isLoggedIn, function(req, res) {
try {
if(req.user.admin) {
var id = req.body.id;
var name = req.body.name;
var defaultPrice = req.body.defaultPrice;
var measures = req.body.measures;
sequelize.models.Item.findById(id, {}).then(function(item) {
item.name = name;
item.defaultPrice = defaultPrice;
item.measures = measures;
return item.save();
}).then(function() {
res.json({result: 'success'});
}).catch(function(err) {
console.log(err);
res.json({result: 'failure'});
});
}
} catch(e) {console.log(e);} } catch(e) {console.log(e);}
}); });

View File

@@ -23,11 +23,6 @@ module.exports = {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false allowNull: false
}, },
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
},
createdAt: { createdAt: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false allowNull: false
@@ -35,9 +30,15 @@ module.exports = {
updatedAt: { updatedAt: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false allowNull: false
},
deletedAt: {
type: DataTypes.DATE,
allowNull: true
} }
}, { }, {
charset: 'utf8' charset: 'utf8',
timestamps: true,
paranoid: true
}); });
}, },

View File

@@ -15,11 +15,6 @@ module.exports = {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false allowNull: false
}, },
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
},
createdAt: { createdAt: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false allowNull: false
@@ -27,9 +22,15 @@ module.exports = {
updatedAt: { updatedAt: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false allowNull: false
},
deletedAt: {
type: DataTypes.DATE,
allowNull: true
} }
}, { }, {
charset: 'utf8' charset: 'utf8',
timestamps: true,
paranoid: true
}); });
}, },

View File

@@ -15,11 +15,6 @@ module.exports = {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false allowNull: false
}, },
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
},
createdAt: { createdAt: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false allowNull: false
@@ -27,9 +22,15 @@ module.exports = {
updatedAt: { updatedAt: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false allowNull: false
},
deletedAt: {
type: DataTypes.DATE,
allowNull: true
} }
}, { }, {
charset: 'utf8' charset: 'utf8',
timestamps: true,
paranoid: true
}); });
}, },

View File

@@ -17,11 +17,6 @@ module.exports = {
field: 'name', field: 'name',
allowNull: false allowNull: false
}, },
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
},
categoryId: { categoryId: {
type: Sequelize.INTEGER, type: Sequelize.INTEGER,
references: { references: {
@@ -38,9 +33,15 @@ module.exports = {
updatedAt: { updatedAt: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false allowNull: false
},
deletedAt: {
type: DataTypes.DATE,
allowNull: true
} }
}, { }, {
charset: 'utf8' charset: 'utf8',
timestamps: true,
paranoid: true
}); });
}, },

View File

@@ -23,11 +23,6 @@ module.exports = {
type: DataTypes.DECIMAL(9,2), type: DataTypes.DECIMAL(9,2),
allowNull: false allowNull: false
}, },
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
},
subcategoryId: { subcategoryId: {
type: Sequelize.INTEGER, type: Sequelize.INTEGER,
references: { references: {
@@ -44,9 +39,15 @@ module.exports = {
updatedAt: { updatedAt: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false allowNull: false
},
deletedAt: {
type: DataTypes.DATE,
allowNull: true
} }
}, { }, {
charset: 'utf8' charset: 'utf8',
timestamps: true,
paranoid: true
}); });
}, },

View File

@@ -58,9 +58,15 @@ module.exports = {
updatedAt: { updatedAt: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false allowNull: false
},
deletedAt: {
type: DataTypes.DATE,
allowNull: true
} }
}, { }, {
charset: 'utf8' charset: 'utf8',
timestamps: true,
paranoid: true
}); });
}, },

View File

@@ -13,13 +13,21 @@ module.exports = function(sequelize, DataTypes) {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false allowNull: false
}, },
visible: { createdAt: {
type: DataTypes.BOOLEAN, type: DataTypes.DATE,
allowNull: false, allowNull: false
defaultValue: true },
updatedAt: {
type: DataTypes.DATE,
allowNull: false
},
deletedAt: {
type: DataTypes.DATE,
allowNull: true
} }
}, { }, {
freezeTableName: true, // Model tableName will be the same as the model name freezeTableName: true, // Model tableName will be the same as the model name
paranoid: true,
classMethods: { classMethods: {
associate: function(models) { associate: function(models) {
Category.hasMany(models.Subcategory, {as: 'subcategories', foreignKey: {name: 'categoryId', field: 'categoryId'}}); Category.hasMany(models.Subcategory, {as: 'subcategories', foreignKey: {name: 'categoryId', field: 'categoryId'}});

View File

@@ -22,13 +22,21 @@ module.exports = function(sequelize, DataTypes) {
type: DataTypes.DECIMAL(9,2), type: DataTypes.DECIMAL(9,2),
allowNull: false allowNull: false
}, },
visible: { createdAt: {
type: DataTypes.BOOLEAN, type: DataTypes.DATE,
allowNull: false, allowNull: false
defaultValue: true },
updatedAt: {
type: DataTypes.DATE,
allowNull: false
},
deletedAt: {
type: DataTypes.DATE,
allowNull: true
} }
}, { }, {
freezeTableName: true, // Model tableName will be the same as the model name freezeTableName: true, // Model tableName will be the same as the model name
paranoid: true,
classMethods: { classMethods: {
associate: function(models) { associate: function(models) {
Item.belongsTo(models.Subcategory, {as: 'subcategory', foreignKey: {name: 'subcategoryId', field: 'subcategoryId'}}); Item.belongsTo(models.Subcategory, {as: 'subcategory', foreignKey: {name: 'subcategoryId', field: 'subcategoryId'}});

View File

@@ -20,13 +20,9 @@ module.exports = function(sequelize, DataTypes) {
postfix: { postfix: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false allowNull: false
},
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
} }
}, { }, {
freezeTableName: true // Model tableName will be the same as the model name freezeTableName: true, // Model tableName will be the same as the model
paranoid: true
}); });
}; };

View File

@@ -21,9 +21,22 @@ module.exports = function(sequelize, DataTypes) {
//GAAP standard is to use DECIMAL(13,4) for precision when dealing with money. 13 digits before the decimal, and 4 after it. //GAAP standard is to use DECIMAL(13,4) for precision when dealing with money. 13 digits before the decimal, and 4 after it.
type: DataTypes.DECIMAL(13,4), type: DataTypes.DECIMAL(13,4),
allowNull: false allowNull: false
},
createdAt: {
type: DataTypes.DATE,
allowNull: false
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false
},
deletedAt: {
type: DataTypes.DATE,
allowNull: true
} }
}, { }, {
freezeTableName: true, // Model tableName will be the same as the model name freezeTableName: true, // Model tableName will be the same as the model name
paranoid: true,
classMethods: { classMethods: {
associate: function(models) { associate: function(models) {
Sale.belongsTo(models.Item, {as: 'item', foreignKey: {name: 'itemId', field: 'itemId'}}); Sale.belongsTo(models.Item, {as: 'item', foreignKey: {name: 'itemId', field: 'itemId'}});

View File

@@ -15,13 +15,21 @@ module.exports = function(sequelize, DataTypes) {
field: 'name', field: 'name',
allowNull: false allowNull: false
}, },
visible: { createdAt: {
type: DataTypes.BOOLEAN, type: DataTypes.DATE,
allowNull: false, allowNull: false
defaultValue: true },
updatedAt: {
type: DataTypes.DATE,
allowNull: false
},
deletedAt: {
type: DataTypes.DATE,
allowNull: true
} }
}, { }, {
freezeTableName: true, // Model tableName will be the same as the model name freezeTableName: true, // Model tableName will be the same as the model name
paranoid: true,
classMethods: { classMethods: {
associate: function(models) { associate: function(models) {
Subcategory.belongsTo(models.Category, {as: 'category', foreignKey: {name: 'categoryId', field: 'categoryId'}}); Subcategory.belongsTo(models.Category, {as: 'category', foreignKey: {name: 'categoryId', field: 'categoryId'}});

View File

@@ -13,12 +13,20 @@ module.exports = function(sequelize, DataTypes) {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false allowNull: false
}, },
visible: { createdAt: {
type: DataTypes.BOOLEAN, type: DataTypes.DATE,
allowNull: false, allowNull: false
defaultValue: true },
updatedAt: {
type: DataTypes.DATE,
allowNull: false
},
deletedAt: {
type: DataTypes.DATE,
allowNull: true
} }
}, { }, {
freezeTableName: true // Model tableName will be the same as the model name freezeTableName: true, // Model tableName will be the same as the model name,
paranoid: true
}); });
}; };

184
public/admin/Venues.html Normal file
View File

@@ -0,0 +1,184 @@
<div id="venues" class="page">
<div class="col-sm-12 col-sm-offset-0">
<h1><span class="fa fa-users"></span> Manage Venues</h1>
<div class="col-sm-6">
<div class="dt-buttons btn-group" style="display: inline-block">
<a id="createButton" class="btn btn-default buttons-create" tabindex="0" href="javaScript:void(0);"><span>New</span></a>
<a id="editButton" class="btn btn-default buttons-selected buttons-edit" tabindex="0" href="javaScript:void(0);"><span>Edit</span></a>
<a id="deleteButton" class="btn btn-default buttons-selected buttons-remove" tabindex="0" href="javaScript:void(0);"><span>Delete</span></a>
</div>
<div class="checkbox checkbox-slider checkbox-slider--b-flat" style="display: inline-block; margin-left: 20px">
<label>
<input type="checkbox" id="includeDeletedToggle"><span style="margin-left: 0; padding-left: 24px;">Include Deleted</span>
</label>
</div>
</div>
<table id="venue-table" class="table table-striped table-hover">
<thead>
<tr>
<th data-key-name="name">Name</th>
<!--<th data-key-name="admin">Admin</th>-->
</tr>
</thead>
</table>
<div id="createDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Create Venue</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" id="createDialog_NameField" tabindex="0">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-md" id="createDialog_CreateButton" tabindex="0">Create</button>
<button type="button" class="btn" data-dismiss="modal" tabindex="0">Cancel</button>
</div>
</div>
</div>
<div id="editDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Edit Venue</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" id="editDialog_NameField" tabindex="0">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-md" id="editDialog_SaveButton" tabindex="0">Save</button>
<button type="button" class="btn" data-dismiss="modal" tabindex="0">Cancel</button>
</div>
</div>
</div>
<div id="deleteDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Delete Venue</h4>
</div>
<div class="modal-body">
Are you certain you wish to delete the venue <span id="deleteDialog_NameField"></span>?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning btn-md" id="deleteDialog_DeleteButton" tabindex="0">Delete</button>
<button type="button" class="btn btn-default" data-dismiss="modal" tabindex="1">Cancel</button>
</div>
</div>
</div>
<script language="JavaScript" type="text/javascript">
$(function() {
//# sourceURL=venues.html
var dataTable = new LinkedTable($('#venue-table'), {
url: "venues/list",
attr: "data-key-name",
selection: "row",
parameters: function() {
return {showDeleted: $('#includeDeletedToggle').is(":checked") ? true : false};
},
postAddRowHandler: function($row, dataObject) {
if(dataObject.deletedAt) {
$("td:first", $row).prepend("<span class='glyphicon glyphicon-remove-circle' style='margin-right: 10px;' aria-hidden='true'></span>");
}
}
});
//Call the refresh user table function once initially.
dataTable.refresh();
//---- Create Dialog ----
$("#createButton").on("click", function(event) {
$("#createDialog").modal();
});
$("#createDialog_CreateButton").on("click", function(event) {
try {
$.post("/admin/venues/create", {
name: $("#createDialog_NameField").val()
}, function(data) {
if(data.result == "success") {
$("#createDialog").modal("hide");
dataTable.refresh();
}
else {
alert(data.result);
}
}, "json");
} catch(e) {
alert(e);
}
});
$("#createDialog").on('shown.bs.modal', function() {
$('#createDialog_NameField').focus();
});
//----------------------------
//---- Delete Dialog ----
$("#deleteButton").on("click", function(event) {
//debugger;
if(dataTable.getSelectedRow() != null) {
$("#deleteDialog_NameField").html(dataTable.getSelectedRow().data("model").name);
$("#deleteDialog").modal();
}
});
$("#deleteDialog_DeleteButton").on("click", function(event) {
if(dataTable.getSelectedRow() != null) {
$.post("/admin/venues/delete", {id: dataTable.getSelectedRow().data("model").id}, function(data) {
if(data.result == "success") {
$("#deleteDialog").modal("hide");
dataTable.refresh();
}
else {
alert(data.result);
}
}, "json");
}
});
//-----------------------------
//----- Edit Dialog ----
$("#editButton").on("click", function(event) {
//debugger;
if(dataTable.getSelectedRow() != null) {
$('#editDialog_NameField').val(dataTable.getSelectedRow().data("model").name);
$("#editDialog").modal();
}
});
$("#editDialog_SaveButton").on("click", function(event) {
if(dataTable.getSelectedRow() != null) {
$.post("/admin/venues/edit", {
id: dataTable.getSelectedRow().data("model").id,
name: $("#editDialog_NameField").val()
}, function(data) {
if(data.result == "success") {
$("#editDialog").modal("hide");
dataTable.refresh();
}
else {
alert(data.result);
}
}, "json");
}
});
$("#editDialog").on('shown.bs.modal', function() {
$('#editDialog_NameField').focus().select();
});
//---------------------
$('#includeDeletedToggle').on('click', function(event) {
dataTable.refresh();
});
});
</script>
</div>
</div>

View File

View File

@@ -0,0 +1,183 @@
<div id="categories" class="page">
<div class="col-sm-12 col-sm-offset-0">
<h1><span class="fa fa-users"></span> Manage Categories</h1>
<div class="col-sm-6">
<div class="dt-buttons btn-group" style="display: inline-block">
<a id="createButton" class="btn btn-default buttons-create" tabindex="0" href="javaScript:void(0);"><span>New</span></a>
<a id="editButton" class="btn btn-default buttons-selected buttons-edit" tabindex="0" href="javaScript:void(0);"><span>Edit</span></a>
<a id="deleteButton" class="btn btn-default buttons-selected buttons-remove" tabindex="0" href="javaScript:void(0);"><span>Delete</span></a>
</div>
<div class="checkbox checkbox-slider checkbox-slider--b-flat" style="display: inline-block; margin-left: 20px">
<label>
<input type="checkbox" id="includeDeletedToggle"><span style="margin-left: 0; padding-left: 24px;">Include Deleted</span>
</label>
</div>
</div>
<table id="category-table" class="table table-striped table-hover">
<thead>
<tr>
<th data-key-name="name">Name</th>
</tr>
</thead>
</table>
<div id="createDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Create Category</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" id="createDialog_NameField" tabindex="0">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-md" id="createDialog_CreateButton" tabindex="0">Create</button>
<button type="button" class="btn" data-dismiss="modal" tabindex="0">Cancel</button>
</div>
</div>
</div>
<div id="editDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Edit Category</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" id="editDialog_NameField" tabindex="0">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-md" id="editDialog_SaveButton" tabindex="0">Save</button>
<button type="button" class="btn" data-dismiss="modal" tabindex="0">Cancel</button>
</div>
</div>
</div>
<div id="deleteDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Delete Category</h4>
</div>
<div class="modal-body">
Are you certain you wish to delete the category <span id="deleteDialog_NameField"></span>?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning btn-md" id="deleteDialog_DeleteButton" tabindex="0">Delete</button>
<button type="button" class="btn btn-default" data-dismiss="modal" tabindex="1">Cancel</button>
</div>
</div>
</div>
<script language="JavaScript" type="text/javascript">
$(function() {
//# sourceURL=categories.html
var dataTable = new LinkedTable($('#category-table'), {
url: "categories/list",
attr: "data-key-name",
selection: "row",
parameters: function() {
return {showDeleted: $('#includeDeletedToggle').is(":checked") ? true : false};
},
postAddRowHandler: function($row, dataObject) {
if(dataObject.deletedAt) {
$("td:first", $row).prepend("<span class='glyphicon glyphicon-remove-circle' style='margin-right: 10px;' aria-hidden='true'></span>");
}
}
});
//Call the refresh user table function once initially.
dataTable.refresh();
//---- Create Dialog ----
$("#createButton").on("click", function(event) {
$("#createDialog").modal();
});
$("#createDialog_CreateButton").on("click", function(event) {
try {
$.post("/admin/categories/create", {
name: $("#createDialog_NameField").val()
}, function(data) {
if(data.result == "success") {
$("#createDialog").modal("hide");
dataTable.refresh();
}
else {
alert(data.result);
}
}, "json");
} catch(e) {
alert(e);
}
});
$("#createDialog").on('shown.bs.modal', function() {
$('#createDialog_NameField').focus();
});
//----------------------------
//---- Delete Dialog ----
$("#deleteButton").on("click", function(event) {
//debugger;
if(dataTable.getSelectedRow() != null) {
$("#deleteDialog_NameField").html(dataTable.getSelectedRow().data("model").name);
$("#deleteDialog").modal();
}
});
$("#deleteDialog_DeleteButton").on("click", function(event) {
if(dataTable.getSelectedRow() != null) {
$.post("/admin/categories/delete", {id: dataTable.getSelectedRow().data("model").id}, function(data) {
if(data.result == "success") {
$("#deleteDialog").modal("hide");
dataTable.refresh();
}
else {
alert(data.result);
}
}, "json");
}
});
//-----------------------------
//----- Edit Dialog ----
$("#editButton").on("click", function(event) {
//debugger;
if(dataTable.getSelectedRow() != null) {
$('#editDialog_NameField').val(dataTable.getSelectedRow().data("model").name);
$("#editDialog").modal();
}
});
$("#editDialog_SaveButton").on("click", function(event) {
if(dataTable.getSelectedRow() != null) {
$.post("/admin/categories/edit", {
id: dataTable.getSelectedRow().data("model").id,
name: $("#editDialog_NameField").val()
}, function(data) {
if(data.result == "success") {
$("#editDialog").modal("hide");
dataTable.refresh();
}
else {
alert(data.result);
}
}, "json");
}
});
$("#editDialog").on('shown.bs.modal', function() {
$('#editDialog_NameField').focus().select();
});
//---------------------
$('#includeDeletedToggle').on('click', function(event) {
dataTable.refresh();
});
});
</script>
</div>
</div>

View File

@@ -0,0 +1,2 @@
#categories {
}

195
public/admin/css/bootstrap-switch.css vendored Normal file
View File

@@ -0,0 +1,195 @@
/* ========================================================================
* bootstrap-switch - v3.3.2
* http://www.bootstrap-switch.org
* ========================================================================
* Copyright 2012-2013 Mattia Larentis
*
* ========================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================================
*/
.bootstrap-switch {
display: inline-block;
direction: ltr;
cursor: pointer;
border-radius: 4px;
border: 1px solid;
border-color: #cccccc;
position: relative;
text-align: left;
overflow: hidden;
line-height: 8px;
z-index: 0;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
vertical-align: middle;
-webkit-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
-o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}
.bootstrap-switch .bootstrap-switch-container {
display: inline-block;
top: 0;
border-radius: 4px;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.bootstrap-switch .bootstrap-switch-handle-on,
.bootstrap-switch .bootstrap-switch-handle-off,
.bootstrap-switch .bootstrap-switch-label {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
cursor: pointer;
display: inline-block !important;
height: 100%;
padding: 6px 12px;
font-size: 14px;
line-height: 20px;
}
.bootstrap-switch .bootstrap-switch-handle-on,
.bootstrap-switch .bootstrap-switch-handle-off {
text-align: center;
z-index: 1;
}
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-primary,
.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-primary {
color: #fff;
background: #337ab7;
}
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-info,
.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-info {
color: #fff;
background: #5bc0de;
}
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-success,
.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-success {
color: #fff;
background: #5cb85c;
}
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-warning,
.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-warning {
background: #f0ad4e;
color: #fff;
}
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-danger,
.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-danger {
color: #fff;
background: #d9534f;
}
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-default,
.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-default {
color: #000;
background: #eeeeee;
}
.bootstrap-switch .bootstrap-switch-label {
text-align: center;
margin-top: -1px;
margin-bottom: -1px;
z-index: 100;
color: #333333;
background: #ffffff;
}
.bootstrap-switch .bootstrap-switch-handle-on {
border-bottom-left-radius: 3px;
border-top-left-radius: 3px;
}
.bootstrap-switch .bootstrap-switch-handle-off {
border-bottom-right-radius: 3px;
border-top-right-radius: 3px;
}
.bootstrap-switch input[type='radio'],
.bootstrap-switch input[type='checkbox'] {
position: absolute !important;
top: 0;
left: 0;
margin: 0;
z-index: -1;
opacity: 0;
filter: alpha(opacity=0);
}
.bootstrap-switch.bootstrap-switch-mini .bootstrap-switch-handle-on,
.bootstrap-switch.bootstrap-switch-mini .bootstrap-switch-handle-off,
.bootstrap-switch.bootstrap-switch-mini .bootstrap-switch-label {
padding: 1px 5px;
font-size: 12px;
line-height: 1.5;
}
.bootstrap-switch.bootstrap-switch-small .bootstrap-switch-handle-on,
.bootstrap-switch.bootstrap-switch-small .bootstrap-switch-handle-off,
.bootstrap-switch.bootstrap-switch-small .bootstrap-switch-label {
padding: 5px 10px;
font-size: 12px;
line-height: 1.5;
}
.bootstrap-switch.bootstrap-switch-large .bootstrap-switch-handle-on,
.bootstrap-switch.bootstrap-switch-large .bootstrap-switch-handle-off,
.bootstrap-switch.bootstrap-switch-large .bootstrap-switch-label {
padding: 6px 16px;
font-size: 18px;
line-height: 1.3333333;
}
.bootstrap-switch.bootstrap-switch-disabled,
.bootstrap-switch.bootstrap-switch-readonly,
.bootstrap-switch.bootstrap-switch-indeterminate {
cursor: default !important;
}
.bootstrap-switch.bootstrap-switch-disabled .bootstrap-switch-handle-on,
.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-handle-on,
.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-handle-on,
.bootstrap-switch.bootstrap-switch-disabled .bootstrap-switch-handle-off,
.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-handle-off,
.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-handle-off,
.bootstrap-switch.bootstrap-switch-disabled .bootstrap-switch-label,
.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-label,
.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-label {
opacity: 0.5;
filter: alpha(opacity=50);
cursor: default !important;
}
.bootstrap-switch.bootstrap-switch-animate .bootstrap-switch-container {
-webkit-transition: margin-left 0.5s;
-o-transition: margin-left 0.5s;
transition: margin-left 0.5s;
}
.bootstrap-switch.bootstrap-switch-inverse .bootstrap-switch-handle-on {
border-bottom-left-radius: 0;
border-top-left-radius: 0;
border-bottom-right-radius: 3px;
border-top-right-radius: 3px;
}
.bootstrap-switch.bootstrap-switch-inverse .bootstrap-switch-handle-off {
border-bottom-right-radius: 0;
border-top-right-radius: 0;
border-bottom-left-radius: 3px;
border-top-left-radius: 3px;
}
.bootstrap-switch.bootstrap-switch-focused {
border-color: #66afe9;
outline: 0;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
}
.bootstrap-switch.bootstrap-switch-on .bootstrap-switch-label,
.bootstrap-switch.bootstrap-switch-inverse.bootstrap-switch-off .bootstrap-switch-label {
border-bottom-right-radius: 3px;
border-top-right-radius: 3px;
}
.bootstrap-switch.bootstrap-switch-off .bootstrap-switch-label,
.bootstrap-switch.bootstrap-switch-inverse.bootstrap-switch-on .bootstrap-switch-label {
border-bottom-left-radius: 3px;
border-top-left-radius: 3px;
}

File diff suppressed because one or more lines are too long

View File

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 106 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -21,10 +21,12 @@
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css"> <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">
<link rel="stylesheet" href="/admin/css/bootstrap/bootstrap.min.css"> <link rel="stylesheet" href="/admin/css/bootstrap/bootstrap.min.css">
<link rel="stylesheet" href="/admin/css/jquery-ui-1.11.4/jquery-ui.min.css"> <link rel="stylesheet" href="/admin/css/jquery-ui-1.11.4/jquery-ui.min.css">
<link rel="stylesheet" href="/admin/css/titatoggle-dist-min.css">
<script type="text/javascript" language="JavaScript" src="js/jquery-1.11.3.min.js"></script> <script type="text/javascript" language="JavaScript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" language="JavaScript" src="js/jquery-migrate-1.2.1.min.js"></script> <script type="text/javascript" language="JavaScript" src="js/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" language="JavaScript" src="js/jquery.history.js"></script> <script type="text/javascript" language="JavaScript" src="js/jquery.history.js"></script>
<script type="text/javascript" language="JavaScript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" language="JavaScript" src="js/layout.js"></script> <script type="text/javascript" language="JavaScript" src="js/layout.js"></script>
<script type="text/javascript" language="JavaScript" src="js/jquery.cycle.min.js"></script> <script type="text/javascript" language="JavaScript" src="js/jquery.cycle.min.js"></script>
<script type="text/javascript" language="JavaScript" src="js/jquery.cycle2.min.js"></script> <script type="text/javascript" language="JavaScript" src="js/jquery.cycle2.min.js"></script>
@@ -32,27 +34,28 @@
<script type="text/javascript" language="JavaScript" src="js/scroller.js"></script> <script type="text/javascript" language="JavaScript" src="js/scroller.js"></script>
<script type="text/javascript" language="JavaScript" src="js/framework_lite.js"></script> <script type="text/javascript" language="JavaScript" src="js/framework_lite.js"></script>
<script type="text/javascript" language="JavaScript" src="js/main.js"></script> <script type="text/javascript" language="JavaScript" src="js/main.js"></script>
<script type="text/javascript" language="JavaScript" src="js/awesomplete.min.js"></script>
<script type="text/javascript" language="JavaScript" src="js/jquery-ui-1.11.4.min.js"></script>
<script type="text/javascript" language="JavaScript" src="js/jquery.fancytree-all.min.js"></script>
<script type="text/javascript" language="JavaScript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" language="JavaScript" src="js/LinkedTable.js"></script> <script type="text/javascript" language="JavaScript" src="js/LinkedTable.js"></script>
<!--
<script type="text/javascript" language="JavaScript"> <script type="text/javascript" language="JavaScript">
function check(x) { function check(x) {
alert(x); alert(x);
} }
</script> </script>
-->
</head> </head>
<body> <body>
<div id="overall"> <div id="overall">
<div id="page"> <div id="page">
<div id="menu"><!-- Note: Comment out spacing between the elements since the browser will interpret the spaces as characters to be displayed. <div id="menu"><!-- Note: Comment out spacing between the elements since the browser will interpret the spaces as characters to be displayed.
--><a href="#!/dataEntry">Data Entry</a><!-- --><a href="#!/dataEntry">Sales</a><!--
--><a href="#!/dataEditors">Edit</a><!-- --><a href="#!/categories">Categories</a><!--
--><a href="#!/users">Manage Users</a><!-- --><a href="#!/subcategories">Subcategories</a><!--
--><a style="position: absolute; right: 0px;" href="/logout">Log Out</a><!-- --><a href="#!/items">Items</a><!--
--><a href="#!/venues">Venues</a><!--
--><a href="#!/measures">Measures</a><!--
--><a href="#!/users">Users</a><!--
--><a style="position: absolute; right: 0px;" href="logout">Log Out</a><!--
--></div> --></div>
<div id="menuBackground"></div> <div id="menuBackground"></div>
<div id="head"> <div id="head">

0
public/admin/items.css Normal file
View File

207
public/admin/items.html Normal file
View File

@@ -0,0 +1,207 @@
<div id="items" class="page">
<div class="col-sm-12 col-sm-offset-0">
<h1><span class="fa fa-users"></span> Manage Items</h1>
<div class="col-sm-6">
<div class="dt-buttons btn-group" style="display: inline-block">
<a id="createButton" class="btn btn-default buttons-create" tabindex="0" href="javaScript:void(0);"><span>New</span></a>
<a id="editButton" class="btn btn-default buttons-selected buttons-edit" tabindex="0" href="javaScript:void(0);"><span>Edit</span></a>
<a id="deleteButton" class="btn btn-default buttons-selected buttons-remove" tabindex="0" href="javaScript:void(0);"><span>Delete</span></a>
</div>
<div class="checkbox checkbox-slider checkbox-slider--b-flat" style="display: inline-block; margin-left: 20px">
<label>
<input type="checkbox" id="includeDeletedToggle"><span style="margin-left: 0; padding-left: 24px;">Include Deleted</span>
</label>
</div>
</div>
<table id="item-table" class="table table-striped table-hover">
<thead>
<tr>
<th data-key-name="name">Name</th>
<th data-key-name="defaultPrice">Default Price</th>
<th data-key-name="measures">Measures</th>
</tr>
</thead>
</table>
<div id="createDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Create Item</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" id="createDialog_NameField" tabindex="0">
</div>
<div class="form-group">
<label>Default Price</label>
<input type="text" class="form-control" name="name" id="createDialog_DefaultPriceField" tabindex="0">
</div>
<div class="form-group">
<label>Measures</label>
<input type="text" class="form-control" name="name" id="createDialog_MeasuresField" tabindex="0">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-md" id="createDialog_CreateButton" tabindex="0">Create</button>
<button type="button" class="btn" data-dismiss="modal" tabindex="0">Cancel</button>
</div>
</div>
</div>
<div id="editDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Edit Item</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" id="editDialog_NameField" tabindex="0">
</div>
<div class="form-group">
<label>Default Price</label>
<input type="text" class="form-control" name="name" id="editDialog_DefaultPriceField" tabindex="0">
</div>
<div class="form-group">
<label>Measures</label>
<input type="text" class="form-control" name="name" id="editDialog_MeasuresField" tabindex="0">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-md" id="editDialog_SaveButton" tabindex="0">Save</button>
<button type="button" class="btn" data-dismiss="modal" tabindex="0">Cancel</button>
</div>
</div>
</div>
<div id="deleteDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Delete Item</h4>
</div>
<div class="modal-body">
Are you certain you wish to delete the item <span id="deleteDialog_NameField"></span>?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning btn-md" id="deleteDialog_DeleteButton" tabindex="0">Delete</button>
<button type="button" class="btn btn-default" data-dismiss="modal" tabindex="1">Cancel</button>
</div>
</div>
</div>
<script language="JavaScript" type="text/javascript">
$(function() {
//# sourceURL=items.html
var dataTable = new LinkedTable($('#items-table'), {
url: "items/list",
attr: "data-key-name",
selection: "row",
parameters: function() {
return {showDeleted: $('#includeDeletedToggle').is(":checked") ? true : false};
},
postAddRowHandler: function($row, dataObject) {
if(dataObject.deletedAt) {
$("td:first", $row).prepend("<span class='glyphicon glyphicon-remove-circle' style='margin-right: 10px;' aria-hidden='true'></span>");
}
}
});
//Call the refresh user table function once initially.
dataTable.refresh();
//---- Create Dialog ----
$("#createButton").on("click", function(event) {
$("#createDialog").modal();
});
$("#createDialog_CreateButton").on("click", function(event) {
try {
$.post("/admin/items/create", {
name: $("#createDialog_NameField").val(),
defaultPrice: $("#createDialog_DefaultPriceField").val(),
measures: $("#createDialog_MeasuresField").val()
}, function(data) {
if(data.result == "success") {
$("#createDialog").modal("hide");
dataTable.refresh();
}
else {
alert(data.result);
}
}, "json");
} catch(e) {
alert(e);
}
});
$("#createDialog").on('shown.bs.modal', function() {
$('#createDialog_NameField').focus();
});
//----------------------------
//---- Delete Dialog ----
$("#deleteButton").on("click", function(event) {
//debugger;
if(dataTable.getSelectedRow() != null) {
$("#deleteDialog_NameField").html(dataTable.getSelectedRow().data("model").name);
$("#deleteDialog").modal();
}
});
$("#deleteDialog_DeleteButton").on("click", function(event) {
if(dataTable.getSelectedRow() != null) {
$.post("/admin/items/delete", {id: dataTable.getSelectedRow().data("model").id}, function(data) {
if(data.result == "success") {
$("#deleteDialog").modal("hide");
dataTable.refresh();
}
else {
alert(data.result);
}
}, "json");
}
});
//-----------------------------
//----- Edit Dialog ----
$("#editButton").on("click", function(event) {
//debugger;
if(dataTable.getSelectedRow() != null) {
$('#editDialog_NameField').val(dataTable.getSelectedRow().data("model").name);
$('#editDialog_DefaultPriceField').val(dataTable.getSelectedRow().data("model").defaultPrice);
$('#editDialog_MeasuresField').val(dataTable.getSelectedRow().data("model").measures);
$("#editDialog").modal();
}
});
$("#editDialog_SaveButton").on("click", function(event) {
if(dataTable.getSelectedRow() != null) {
$.post("/admin/items/edit", {
id: dataTable.getSelectedRow().data("model").id,
name: $("#editDialog_NameField").val(),
defaultPrice: $("#editDialog_DefaultPriceField").val(),
measures: $("#editDialog_MeasuresField").val()
}, function(data) {
if(data.result == "success") {
$("#editDialog").modal("hide");
dataTable.refresh();
}
else {
alert(data.result);
}
}, "json");
}
});
$("#editDialog").on('shown.bs.modal', function() {
$('#editDialog_NameField').focus().select();
});
//---------------------
$('#includeDeletedToggle').on('click', function(event) {
dataTable.refresh();
});
});
</script>
</div>
</div>

2
public/admin/items.styl Normal file
View File

@@ -0,0 +1,2 @@
#items {
}

View File

@@ -0,0 +1,149 @@
"use strict";
var LinkedTreeTable;
+function($) {
//Pass an element (jquery or html reference), an options object (see DEFAULTS), and an array of node metadata objects (see NODE_DEFAULTS).
LinkedTreeTable = function(element, options, nodeMetadata) {
var _this = this;
this.$element = $(element);
this.options = $.extend({}, LinkedTreeTable.DEFAULTS, options);
this.nodes = [];
this.$selectedRow = null;
this.selectionHandler = function(event) {
$(this).addClass(_this.options.selectionCSS).siblings().removeClass(_this.options.selectionCSS);
_this.$selectedRow = $(this);
};
this.addNodeMetadata = function(nodeMetadata) {
nodeMetadata = $.extend({}, LinkedTreeTable.NODE_DEFAULTS, nodeMetadata);
var nodes = this.nodes[nodeMetadata.type];
nodeMetadata.cls = "NODE";
if(typeof nodes == 'object') {
if(nodes.cls == 'NODE') {
this.nodes[nodeMetadata.type] = [nodes, nodeMetadata];
}
else {
nodes.push(nodeMetadata);
}
}
else {
this.nodes[nodeMetadata.type] = nodeMetadata
}
};
//Add the node metadata to the mapping.
for(var index = 0; index < nodeMetadata.length; index++) {
this.addNodeMetadata(nodeMetadata[index]);
}
};
LinkedTreeTable.DEFAULTS = {
dataAttr: 'data-key-name', //The property name to use to attach the model sent by the server to the table row created for the data.
typeAttr: 'data-type-name', //The attribute name used to attach the type to the table row.
selectionCSS: 'selected',
selection: 'row', //Currently only row is supported.
getIdHandler: null //Optional global function that gets the id for an object. No ID will be used if not provided, in which case the row will not be re-opened or re-selected after refreshing the data from the server.
};
LinkedTreeTable.NODE_DEFAULTS = {
type: '', //The type name this node metadata applies to. Must be provided. The empty type is used to identify the metadata for collecting root nodes.
url: '', //The absolute or relative path to use to query the initial data. Server is expected to respond with a JSON array of objects.
typeHandler: null, //The optional handler called to determine the type for the model sent by the server. Must return a type name that is then matched to the node metadata to get children.
defaultType: null, //The default type to assign to the node if the type handler does not provide one. This normally should be set, particularly if a handler won't always provide a type.
postAddRowHandler: null, //Optional function that is passed the jquery table row and the data object sent by the server for that row. Allows post processing of the row prior to display.
parameters: null, //Optional function that returns an object, or an object whose attributes are passed to the URL as parameters.
getIdHandler: null //Optional function that gets the id for an object. The global version will be used if this one is not provided.
};
LinkedTreeTable.prototype.getSelectedRow = function() {
return this.$selectedRow;
};
//A function that will clean and rebuild the table displaying all the users.
//Note that each row of the table will have a data element attached to the table row. The key will be "model" and the value will be the object sent by the server.
//Pass an optional table row or data object to reference a node in the tree whose children will be refreshed. If not provided then the root nodes will be refreshed.
LinkedTreeTable.prototype.refresh = function(node) {
var _this = this;
var table = this.$element;
var thead = table.find("thead tr");
var tbody = table.find("tbody");
var selection = this.options.selection;
var dataAttr = this.options.dataAttr;
var selectionHandler = this.selectionHandler;
var params;
//TODO: Need to identify the top most visible row?
//TODO: Otherwise identify the scroll position so we can reset it if necessary?
//TODO: Find the ID's of all rows at this tree level or lower that are open so we can re-open them after refreshing?
//TODO: Otherwise map the new data by ID to the rows at this tree level so we can update the rows instead of replacing them?
if(thead.length == 0) {
return;
}
//Empty or Create the table body.
if(tbody.length != 0) {
//Remove the row selection handler.
if(selection == 'row') this.$element.off('click', 'tbody tr', selectionHandler);
//Empty the table of data.
tbody.empty();
}
else {
tbody = $("<tbody></tbody>");
tbody.appendTo(table);
}
if(typeof this.options.parameters == 'function') {
params = this.options.parameters();
//Must be an object.
if(typeof params != 'object') {
params = {};
}
}
else if(typeof this.options.parameters == 'object') {
params = this.options.parameters;
}
else {params = {};}
$.getJSON(this.options.url, params, function(data) {
var headers = thead.children();
var attributes = [];
//Read the table headers to get the data object keys.
for(var headerIndex = 0; headerIndex < headers.length; headerIndex++) {
var nextHeader = headers[headerIndex];
attributes[headerIndex] = $(nextHeader).attr(dataAttr);
}
//Add the table data.
for(var dataIndex = 0; dataIndex < data.length; dataIndex++) {
var rowData = data[dataIndex];
var row = $("<tr></tr>");
row.appendTo(tbody);
//Save the model attached to the table row. Can be retrieved later to get the model sent by the server.
row.data("model", rowData);
for(var attributeIndex = 0; attributeIndex < attributes.length; attributeIndex++) {
var attribute = attributes[attributeIndex];
var cellData = rowData[attribute];
row.append("<td>" + cellData + "</td>");
}
if(_this.options.postAddRowHandler) {
//Call the optional handler after adding the row, passing the jquery row object, and the row data object sent by the server. Allows post processing on the row (adding classes to the row for example).
_this.options.postAddRowHandler(row, rowData);
}
}
//Setup the row selection handler.
if(selection == 'row') table.on('click', 'tbody tr', selectionHandler);
});
}
}(jQuery);

744
public/admin/js/bootstrap-switch.js vendored Normal file
View File

@@ -0,0 +1,744 @@
/* ========================================================================
* bootstrap-switch - v3.3.2
* http://www.bootstrap-switch.org
* ========================================================================
* Copyright 2012-2013 Mattia Larentis
*
* ========================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================================
*/
(function() {
var slice = [].slice;
(function($, window) {
"use strict";
var BootstrapSwitch;
BootstrapSwitch = (function() {
function BootstrapSwitch(element, options) {
if (options == null) {
options = {};
}
this.$element = $(element);
this.options = $.extend({}, $.fn.bootstrapSwitch.defaults, {
state: this.$element.is(":checked"),
size: this.$element.data("size"),
animate: this.$element.data("animate"),
disabled: this.$element.is(":disabled"),
readonly: this.$element.is("[readonly]"),
indeterminate: this.$element.data("indeterminate"),
inverse: this.$element.data("inverse"),
radioAllOff: this.$element.data("radio-all-off"),
onColor: this.$element.data("on-color"),
offColor: this.$element.data("off-color"),
onText: this.$element.data("on-text"),
offText: this.$element.data("off-text"),
labelText: this.$element.data("label-text"),
handleWidth: this.$element.data("handle-width"),
labelWidth: this.$element.data("label-width"),
baseClass: this.$element.data("base-class"),
wrapperClass: this.$element.data("wrapper-class")
}, options);
this.prevOptions = {};
this.$wrapper = $("<div>", {
"class": (function(_this) {
return function() {
var classes;
classes = ["" + _this.options.baseClass].concat(_this._getClasses(_this.options.wrapperClass));
classes.push(_this.options.state ? _this.options.baseClass + "-on" : _this.options.baseClass + "-off");
if (_this.options.size != null) {
classes.push(_this.options.baseClass + "-" + _this.options.size);
}
if (_this.options.disabled) {
classes.push(_this.options.baseClass + "-disabled");
}
if (_this.options.readonly) {
classes.push(_this.options.baseClass + "-readonly");
}
if (_this.options.indeterminate) {
classes.push(_this.options.baseClass + "-indeterminate");
}
if (_this.options.inverse) {
classes.push(_this.options.baseClass + "-inverse");
}
if (_this.$element.attr("id")) {
classes.push(_this.options.baseClass + "-id-" + (_this.$element.attr("id")));
}
return classes.join(" ");
};
})(this)()
});
this.$container = $("<div>", {
"class": this.options.baseClass + "-container"
});
this.$on = $("<span>", {
html: this.options.onText,
"class": this.options.baseClass + "-handle-on " + this.options.baseClass + "-" + this.options.onColor
});
this.$off = $("<span>", {
html: this.options.offText,
"class": this.options.baseClass + "-handle-off " + this.options.baseClass + "-" + this.options.offColor
});
this.$label = $("<span>", {
html: this.options.labelText,
"class": this.options.baseClass + "-label"
});
this.$element.on("init.bootstrapSwitch", (function(_this) {
return function() {
return _this.options.onInit.apply(element, arguments);
};
})(this));
this.$element.on("switchChange.bootstrapSwitch", (function(_this) {
return function(e) {
if (false === _this.options.onSwitchChange.apply(element, arguments)) {
if (_this.$element.is(":radio")) {
return $("[name='" + (_this.$element.attr('name')) + "']").trigger("previousState.bootstrapSwitch", true);
} else {
return _this.$element.trigger("previousState.bootstrapSwitch", true);
}
}
};
})(this));
this.$container = this.$element.wrap(this.$container).parent();
this.$wrapper = this.$container.wrap(this.$wrapper).parent();
this.$element.before(this.options.inverse ? this.$off : this.$on).before(this.$label).before(this.options.inverse ? this.$on : this.$off);
if (this.options.indeterminate) {
this.$element.prop("indeterminate", true);
}
this._init();
this._elementHandlers();
this._handleHandlers();
this._labelHandlers();
this._formHandler();
this._externalLabelHandler();
this.$element.trigger("init.bootstrapSwitch", this.options.state);
}
BootstrapSwitch.prototype._constructor = BootstrapSwitch;
BootstrapSwitch.prototype.setPrevOptions = function() {
return this.prevOptions = $.extend(true, {}, this.options);
};
BootstrapSwitch.prototype.state = function(value, skip) {
if (typeof value === "undefined") {
return this.options.state;
}
if (this.options.disabled || this.options.readonly) {
return this.$element;
}
if (this.options.state && !this.options.radioAllOff && this.$element.is(":radio")) {
return this.$element;
}
if (this.$element.is(":radio")) {
$("[name='" + (this.$element.attr('name')) + "']").trigger("setPreviousOptions.bootstrapSwitch");
} else {
this.$element.trigger("setPreviousOptions.bootstrapSwitch");
}
if (this.options.indeterminate) {
this.indeterminate(false);
}
value = !!value;
this.$element.prop("checked", value).trigger("change.bootstrapSwitch", skip);
return this.$element;
};
BootstrapSwitch.prototype.toggleState = function(skip) {
if (this.options.disabled || this.options.readonly) {
return this.$element;
}
if (this.options.indeterminate) {
this.indeterminate(false);
return this.state(true);
} else {
return this.$element.prop("checked", !this.options.state).trigger("change.bootstrapSwitch", skip);
}
};
BootstrapSwitch.prototype.size = function(value) {
if (typeof value === "undefined") {
return this.options.size;
}
if (this.options.size != null) {
this.$wrapper.removeClass(this.options.baseClass + "-" + this.options.size);
}
if (value) {
this.$wrapper.addClass(this.options.baseClass + "-" + value);
}
this._width();
this._containerPosition();
this.options.size = value;
return this.$element;
};
BootstrapSwitch.prototype.animate = function(value) {
if (typeof value === "undefined") {
return this.options.animate;
}
value = !!value;
if (value === this.options.animate) {
return this.$element;
}
return this.toggleAnimate();
};
BootstrapSwitch.prototype.toggleAnimate = function() {
this.options.animate = !this.options.animate;
this.$wrapper.toggleClass(this.options.baseClass + "-animate");
return this.$element;
};
BootstrapSwitch.prototype.disabled = function(value) {
if (typeof value === "undefined") {
return this.options.disabled;
}
value = !!value;
if (value === this.options.disabled) {
return this.$element;
}
return this.toggleDisabled();
};
BootstrapSwitch.prototype.toggleDisabled = function() {
this.options.disabled = !this.options.disabled;
this.$element.prop("disabled", this.options.disabled);
this.$wrapper.toggleClass(this.options.baseClass + "-disabled");
return this.$element;
};
BootstrapSwitch.prototype.readonly = function(value) {
if (typeof value === "undefined") {
return this.options.readonly;
}
value = !!value;
if (value === this.options.readonly) {
return this.$element;
}
return this.toggleReadonly();
};
BootstrapSwitch.prototype.toggleReadonly = function() {
this.options.readonly = !this.options.readonly;
this.$element.prop("readonly", this.options.readonly);
this.$wrapper.toggleClass(this.options.baseClass + "-readonly");
return this.$element;
};
BootstrapSwitch.prototype.indeterminate = function(value) {
if (typeof value === "undefined") {
return this.options.indeterminate;
}
value = !!value;
if (value === this.options.indeterminate) {
return this.$element;
}
return this.toggleIndeterminate();
};
BootstrapSwitch.prototype.toggleIndeterminate = function() {
this.options.indeterminate = !this.options.indeterminate;
this.$element.prop("indeterminate", this.options.indeterminate);
this.$wrapper.toggleClass(this.options.baseClass + "-indeterminate");
this._containerPosition();
return this.$element;
};
BootstrapSwitch.prototype.inverse = function(value) {
if (typeof value === "undefined") {
return this.options.inverse;
}
value = !!value;
if (value === this.options.inverse) {
return this.$element;
}
return this.toggleInverse();
};
BootstrapSwitch.prototype.toggleInverse = function() {
var $off, $on;
this.$wrapper.toggleClass(this.options.baseClass + "-inverse");
$on = this.$on.clone(true);
$off = this.$off.clone(true);
this.$on.replaceWith($off);
this.$off.replaceWith($on);
this.$on = $off;
this.$off = $on;
this.options.inverse = !this.options.inverse;
return this.$element;
};
BootstrapSwitch.prototype.onColor = function(value) {
var color;
color = this.options.onColor;
if (typeof value === "undefined") {
return color;
}
if (color != null) {
this.$on.removeClass(this.options.baseClass + "-" + color);
}
this.$on.addClass(this.options.baseClass + "-" + value);
this.options.onColor = value;
return this.$element;
};
BootstrapSwitch.prototype.offColor = function(value) {
var color;
color = this.options.offColor;
if (typeof value === "undefined") {
return color;
}
if (color != null) {
this.$off.removeClass(this.options.baseClass + "-" + color);
}
this.$off.addClass(this.options.baseClass + "-" + value);
this.options.offColor = value;
return this.$element;
};
BootstrapSwitch.prototype.onText = function(value) {
if (typeof value === "undefined") {
return this.options.onText;
}
this.$on.html(value);
this._width();
this._containerPosition();
this.options.onText = value;
return this.$element;
};
BootstrapSwitch.prototype.offText = function(value) {
if (typeof value === "undefined") {
return this.options.offText;
}
this.$off.html(value);
this._width();
this._containerPosition();
this.options.offText = value;
return this.$element;
};
BootstrapSwitch.prototype.labelText = function(value) {
if (typeof value === "undefined") {
return this.options.labelText;
}
this.$label.html(value);
this._width();
this.options.labelText = value;
return this.$element;
};
BootstrapSwitch.prototype.handleWidth = function(value) {
if (typeof value === "undefined") {
return this.options.handleWidth;
}
this.options.handleWidth = value;
this._width();
this._containerPosition();
return this.$element;
};
BootstrapSwitch.prototype.labelWidth = function(value) {
if (typeof value === "undefined") {
return this.options.labelWidth;
}
this.options.labelWidth = value;
this._width();
this._containerPosition();
return this.$element;
};
BootstrapSwitch.prototype.baseClass = function(value) {
return this.options.baseClass;
};
BootstrapSwitch.prototype.wrapperClass = function(value) {
if (typeof value === "undefined") {
return this.options.wrapperClass;
}
if (!value) {
value = $.fn.bootstrapSwitch.defaults.wrapperClass;
}
this.$wrapper.removeClass(this._getClasses(this.options.wrapperClass).join(" "));
this.$wrapper.addClass(this._getClasses(value).join(" "));
this.options.wrapperClass = value;
return this.$element;
};
BootstrapSwitch.prototype.radioAllOff = function(value) {
if (typeof value === "undefined") {
return this.options.radioAllOff;
}
value = !!value;
if (value === this.options.radioAllOff) {
return this.$element;
}
this.options.radioAllOff = value;
return this.$element;
};
BootstrapSwitch.prototype.onInit = function(value) {
if (typeof value === "undefined") {
return this.options.onInit;
}
if (!value) {
value = $.fn.bootstrapSwitch.defaults.onInit;
}
this.options.onInit = value;
return this.$element;
};
BootstrapSwitch.prototype.onSwitchChange = function(value) {
if (typeof value === "undefined") {
return this.options.onSwitchChange;
}
if (!value) {
value = $.fn.bootstrapSwitch.defaults.onSwitchChange;
}
this.options.onSwitchChange = value;
return this.$element;
};
BootstrapSwitch.prototype.destroy = function() {
var $form;
$form = this.$element.closest("form");
if ($form.length) {
$form.off("reset.bootstrapSwitch").removeData("bootstrap-switch");
}
this.$container.children().not(this.$element).remove();
this.$element.unwrap().unwrap().off(".bootstrapSwitch").removeData("bootstrap-switch");
return this.$element;
};
BootstrapSwitch.prototype._width = function() {
var $handles, handleWidth;
$handles = this.$on.add(this.$off);
$handles.add(this.$label).css("width", "");
handleWidth = this.options.handleWidth === "auto" ? Math.max(this.$on.width(), this.$off.width()) : this.options.handleWidth;
$handles.width(handleWidth);
this.$label.width((function(_this) {
return function(index, width) {
if (_this.options.labelWidth !== "auto") {
return _this.options.labelWidth;
}
if (width < handleWidth) {
return handleWidth;
} else {
return width;
}
};
})(this));
this._handleWidth = this.$on.outerWidth();
this._labelWidth = this.$label.outerWidth();
this.$container.width((this._handleWidth * 2) + this._labelWidth);
return this.$wrapper.width(this._handleWidth + this._labelWidth);
};
BootstrapSwitch.prototype._containerPosition = function(state, callback) {
if (state == null) {
state = this.options.state;
}
this.$container.css("margin-left", (function(_this) {
return function() {
var values;
values = [0, "-" + _this._handleWidth + "px"];
if (_this.options.indeterminate) {
return "-" + (_this._handleWidth / 2) + "px";
}
if (state) {
if (_this.options.inverse) {
return values[1];
} else {
return values[0];
}
} else {
if (_this.options.inverse) {
return values[0];
} else {
return values[1];
}
}
};
})(this));
if (!callback) {
return;
}
return setTimeout(function() {
return callback();
}, 50);
};
BootstrapSwitch.prototype._init = function() {
var init, initInterval;
init = (function(_this) {
return function() {
_this.setPrevOptions();
_this._width();
return _this._containerPosition(null, function() {
if (_this.options.animate) {
return _this.$wrapper.addClass(_this.options.baseClass + "-animate");
}
});
};
})(this);
if (this.$wrapper.is(":visible")) {
return init();
}
return initInterval = window.setInterval((function(_this) {
return function() {
if (_this.$wrapper.is(":visible")) {
init();
return window.clearInterval(initInterval);
}
};
})(this), 50);
};
BootstrapSwitch.prototype._elementHandlers = function() {
return this.$element.on({
"setPreviousOptions.bootstrapSwitch": (function(_this) {
return function(e) {
return _this.setPrevOptions();
};
})(this),
"previousState.bootstrapSwitch": (function(_this) {
return function(e) {
_this.options = _this.prevOptions;
if (_this.options.indeterminate) {
_this.$wrapper.addClass(_this.options.baseClass + "-indeterminate");
}
return _this.$element.prop("checked", _this.options.state).trigger("change.bootstrapSwitch", true);
};
})(this),
"change.bootstrapSwitch": (function(_this) {
return function(e, skip) {
var state;
e.preventDefault();
e.stopImmediatePropagation();
state = _this.$element.is(":checked");
_this._containerPosition(state);
if (state === _this.options.state) {
return;
}
_this.options.state = state;
_this.$wrapper.toggleClass(_this.options.baseClass + "-off").toggleClass(_this.options.baseClass + "-on");
if (!skip) {
if (_this.$element.is(":radio")) {
$("[name='" + (_this.$element.attr('name')) + "']").not(_this.$element).prop("checked", false).trigger("change.bootstrapSwitch", true);
}
return _this.$element.trigger("switchChange.bootstrapSwitch", [state]);
}
};
})(this),
"focus.bootstrapSwitch": (function(_this) {
return function(e) {
e.preventDefault();
return _this.$wrapper.addClass(_this.options.baseClass + "-focused");
};
})(this),
"blur.bootstrapSwitch": (function(_this) {
return function(e) {
e.preventDefault();
return _this.$wrapper.removeClass(_this.options.baseClass + "-focused");
};
})(this),
"keydown.bootstrapSwitch": (function(_this) {
return function(e) {
if (!e.which || _this.options.disabled || _this.options.readonly) {
return;
}
switch (e.which) {
case 37:
e.preventDefault();
e.stopImmediatePropagation();
return _this.state(false);
case 39:
e.preventDefault();
e.stopImmediatePropagation();
return _this.state(true);
}
};
})(this)
});
};
BootstrapSwitch.prototype._handleHandlers = function() {
this.$on.on("click.bootstrapSwitch", (function(_this) {
return function(event) {
event.preventDefault();
event.stopPropagation();
_this.state(false);
return _this.$element.trigger("focus.bootstrapSwitch");
};
})(this));
return this.$off.on("click.bootstrapSwitch", (function(_this) {
return function(event) {
event.preventDefault();
event.stopPropagation();
_this.state(true);
return _this.$element.trigger("focus.bootstrapSwitch");
};
})(this));
};
BootstrapSwitch.prototype._labelHandlers = function() {
return this.$label.on({
"click": function(e) {
return e.stopPropagation();
},
"mousedown.bootstrapSwitch touchstart.bootstrapSwitch": (function(_this) {
return function(e) {
if (_this._dragStart || _this.options.disabled || _this.options.readonly) {
return;
}
e.preventDefault();
e.stopPropagation();
_this._dragStart = (e.pageX || e.originalEvent.touches[0].pageX) - parseInt(_this.$container.css("margin-left"), 10);
if (_this.options.animate) {
_this.$wrapper.removeClass(_this.options.baseClass + "-animate");
}
return _this.$element.trigger("focus.bootstrapSwitch");
};
})(this),
"mousemove.bootstrapSwitch touchmove.bootstrapSwitch": (function(_this) {
return function(e) {
var difference;
if (_this._dragStart == null) {
return;
}
e.preventDefault();
difference = (e.pageX || e.originalEvent.touches[0].pageX) - _this._dragStart;
if (difference < -_this._handleWidth || difference > 0) {
return;
}
_this._dragEnd = difference;
return _this.$container.css("margin-left", _this._dragEnd + "px");
};
})(this),
"mouseup.bootstrapSwitch touchend.bootstrapSwitch": (function(_this) {
return function(e) {
var state;
if (!_this._dragStart) {
return;
}
e.preventDefault();
if (_this.options.animate) {
_this.$wrapper.addClass(_this.options.baseClass + "-animate");
}
if (_this._dragEnd) {
state = _this._dragEnd > -(_this._handleWidth / 2);
_this._dragEnd = false;
_this.state(_this.options.inverse ? !state : state);
} else {
_this.state(!_this.options.state);
}
return _this._dragStart = false;
};
})(this),
"mouseleave.bootstrapSwitch": (function(_this) {
return function(e) {
return _this.$label.trigger("mouseup.bootstrapSwitch");
};
})(this)
});
};
BootstrapSwitch.prototype._externalLabelHandler = function() {
var $externalLabel;
$externalLabel = this.$element.closest("label");
return $externalLabel.on("click", (function(_this) {
return function(event) {
event.preventDefault();
event.stopImmediatePropagation();
if (event.target === $externalLabel[0]) {
return _this.toggleState();
}
};
})(this));
};
BootstrapSwitch.prototype._formHandler = function() {
var $form;
$form = this.$element.closest("form");
if ($form.data("bootstrap-switch")) {
return;
}
return $form.on("reset.bootstrapSwitch", function() {
return window.setTimeout(function() {
return $form.find("input").filter(function() {
return $(this).data("bootstrap-switch");
}).each(function() {
return $(this).bootstrapSwitch("state", this.checked);
});
}, 1);
}).data("bootstrap-switch", true);
};
BootstrapSwitch.prototype._getClasses = function(classes) {
var c, cls, i, len;
if (!$.isArray(classes)) {
return [this.options.baseClass + "-" + classes];
}
cls = [];
for (i = 0, len = classes.length; i < len; i++) {
c = classes[i];
cls.push(this.options.baseClass + "-" + c);
}
return cls;
};
return BootstrapSwitch;
})();
$.fn.bootstrapSwitch = function() {
var args, option, ret;
option = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
ret = this;
this.each(function() {
var $this, data;
$this = $(this);
data = $this.data("bootstrap-switch");
if (!data) {
$this.data("bootstrap-switch", data = new BootstrapSwitch(this, option));
}
if (typeof option === "string") {
return ret = data[option].apply(data, args);
}
});
return ret;
};
$.fn.bootstrapSwitch.Constructor = BootstrapSwitch;
return $.fn.bootstrapSwitch.defaults = {
state: true,
size: null,
animate: true,
disabled: false,
readonly: false,
indeterminate: false,
inverse: false,
radioAllOff: false,
onColor: "primary",
offColor: "default",
onText: "ON",
offText: "OFF",
labelText: "&nbsp;",
handleWidth: "auto",
labelWidth: "auto",
baseClass: "bootstrap-switch",
wrapperClass: "wrapper",
onInit: function() {},
onSwitchChange: function() {}
};
})(window.jQuery, window);
}).call(this);

22
public/admin/js/bootstrap-switch.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -75,52 +75,54 @@ function BrainstormFramework() {
} }
this.extractViewData = function(viewData) { this.extractViewData = function(viewData) {
var data = {script: "", metadata: undefined, view: ""}; if(viewData != undefined) {
var start; var data = {script: "", metadata: undefined, view: ""};
var start;
//Remove the escaping that allowed it to be sent as part of a JSON response.// //Remove the escaping that allowed it to be sent as part of a JSON response.//
viewData = this.unescape(viewData); viewData = this.unescape(viewData);
//Strip out any run-once scripts to be run after loading the html.// //Strip out any run-once scripts to be run after loading the html.//
while(viewData.indexOf("<runonce>") != -1) { while(viewData.indexOf("<runonce>") != -1) {
//extract the script.// //extract the script.//
data.script += viewData.substring(viewData.indexOf("<runonce>") + 9, viewData.indexOf("</runonce>")).replace("<!--", "").replace("//-->", ""); data.script += viewData.substring(viewData.indexOf("<runonce>") + 9, viewData.indexOf("</runonce>")).replace("<!--", "").replace("//-->", "");
//Remove the script from the view data.// //Remove the script from the view data.//
viewData = viewData.substring(0, viewData.indexOf("<runonce>")) + viewData.substring(viewData.indexOf("</runonce>") + 10); viewData = viewData.substring(0, viewData.indexOf("<runonce>")) + viewData.substring(viewData.indexOf("</runonce>") + 10);
}
//Detect and remove any metadata.//
if((start = viewData.indexOf('<metadata>')) != -1) {
var end = viewData.indexOf('</metadata>', start + 10);
var metadata = viewData.substring(start, end + 11);
//Remove the metadata from the document.//
viewData = viewData.substring(0, start) + viewData.substring(end + 11);
//Parse the metadata XML.//
data.metadata = $.parseXML(metadata);
}
else if((start = viewData.indexOf('<metadata ')) != -1) {
var end = viewData.indexOf('/>', start + 10);
var metadata = viewData.substring(start, end + 2);
//Remove the metadata from the document.//
viewData = viewData.substring(0, start) + viewData.substring(end + 2);
//Parse the metadata XML.//
data.metadata = $.parseXML(metadata);
}
else if((start = viewData.indexOf('<metadata/>')) != -1) {
viewData = viewData.substring(0, start) + viewData.substring(start + 11);
}
//Strip out any comments.//
while(viewData.indexOf("<!--") != -1) {
//Remove the comment from the view data.//
viewData = viewData.substring(0, viewData.indexOf("<!--")) + viewData.substring(viewData.indexOf("-->") + 3);
}
data.view = viewData;
return data;
} }
//Detect and remove any metadata.//
if((start = viewData.indexOf('<metadata>')) != -1) {
var end = viewData.indexOf('</metadata>', start + 10);
var metadata = viewData.substring(start, end + 11);
//Remove the metadata from the document.//
viewData = viewData.substring(0, start) + viewData.substring(end + 11);
//Parse the metadata XML.//
data.metadata = $.parseXML(metadata);
}
else if((start = viewData.indexOf('<metadata ')) != -1) {
var end = viewData.indexOf('/>', start + 10);
var metadata = viewData.substring(start, end + 2);
//Remove the metadata from the document.//
viewData = viewData.substring(0, start) + viewData.substring(end + 2);
//Parse the metadata XML.//
data.metadata = $.parseXML(metadata);
}
else if((start = viewData.indexOf('<metadata/>')) != -1) {
viewData = viewData.substring(0, start) + viewData.substring(start + 11);
}
//Strip out any comments.//
while(viewData.indexOf("<!--") != -1) {
//Remove the comment from the view data.//
viewData = viewData.substring(0, viewData.indexOf("<!--")) + viewData.substring(viewData.indexOf("-->") + 3);
}
data.view = viewData;
return data;
} }
// //

View File

@@ -4,32 +4,40 @@ var LinkedTable;
+function($) { +function($) {
LinkedTable = function(element, options) { LinkedTable = function(element, options) {
var _this = this;
this.$element = $(element); this.$element = $(element);
this.options = $.extend({}, LinkedTable.DEFAULTS, options); this.options = $.extend({}, LinkedTable.DEFAULTS, options);
this.clickHandler = function(event) { this.$selectedRow = null;
$(this).addClass('highlight').siblings().removeClass('highlight'); this.selectionHandler = function(event) {
$(this).addClass(_this.options.selectionCSS).siblings().removeClass(_this.options.selectionCSS);
_this.$selectedRow = $(this);
}; };
}; };
LinkedTable.DEFAULTS = { LinkedTable.DEFAULTS = {
url: '', //The absolute or relative path to use to query the data. Server is expected to respond with a JSON array of objects. url: '', //The absolute or relative path to use to query the data. Server is expected to respond with a JSON array of objects.
attr: 'data-key-name', attr: 'data-key-name',
selection: 'row' //Currently only row is supported. selectionCSS: 'selected',
selection: 'row', //Currently only row is supported.
postAddRowHandler: null, //Optional function that is passed the jquery table row and the data object sent by the server for that row. Allows post processing of the row prior to display.
parameters: null //Optional function that returns an object, or an object whose attributes are passed to the URL as parameters.
}; };
//TODO LinkedTable.prototype.getSelectedRow = function() {
LinkedTable.prototype.myMethod = function() { return this.$selectedRow;
}; };
//A function that will clean and rebuild the table displaying all the users. //A function that will clean and rebuild the table displaying all the users.
//Note that each row of the table will have a data element attached to the table row. The key will be "model" and the value will be the object sent by the server.
LinkedTable.prototype.refresh = function() { LinkedTable.prototype.refresh = function() {
var _this = this;
var table = this.$element; var table = this.$element;
var thead = table.find("thead tr"); var thead = table.find("thead tr");
var tbody = table.find("tbody"); var tbody = table.find("tbody");
var selection = this.options.selection; var selection = this.options.selection;
var attr = this.options.attr; var attr = this.options.attr;
var clickHandler = this.clickHandler; var selectionHandler = this.selectionHandler;
var params;
if(thead.length == 0) { if(thead.length == 0) {
return; return;
@@ -38,7 +46,7 @@ var LinkedTable;
//Empty or Create the table body. //Empty or Create the table body.
if(tbody.length != 0) { if(tbody.length != 0) {
//Remove the row selection handler. //Remove the row selection handler.
if(selection == 'row') this.$element.off('click', 'tbody tr', clickHandler); if(selection == 'row') this.$element.off('click', 'tbody tr', selectionHandler);
//Empty the table of data. //Empty the table of data.
tbody.empty(); tbody.empty();
} }
@@ -47,7 +55,20 @@ var LinkedTable;
tbody.appendTo(table); tbody.appendTo(table);
} }
$.getJSON("user-data", function(data) { if(typeof this.options.parameters == 'function') {
params = this.options.parameters();
//Must be an object.
if(typeof params != 'object') {
params = {};
}
}
else if(typeof this.options.parameters == 'object') {
params = this.options.parameters;
}
else {params = {};}
$.getJSON(this.options.url, params, function(data) {
var headers = thead.children(); var headers = thead.children();
var attributes = []; var attributes = [];
@@ -64,6 +85,8 @@ var LinkedTable;
var row = $("<tr></tr>"); var row = $("<tr></tr>");
row.appendTo(tbody); row.appendTo(tbody);
//Save the model attached to the table row. Can be retrieved later to get the model sent by the server.
row.data("model", rowData);
for(var attributeIndex = 0; attributeIndex < attributes.length; attributeIndex++) { for(var attributeIndex = 0; attributeIndex < attributes.length; attributeIndex++) {
var attribute = attributes[attributeIndex]; var attribute = attributes[attributeIndex];
@@ -71,10 +94,15 @@ var LinkedTable;
row.append("<td>" + cellData + "</td>"); row.append("<td>" + cellData + "</td>");
} }
if(_this.options.postAddRowHandler) {
//Call the optional handler after adding the row, passing the jquery row object, and the row data object sent by the server. Allows post processing on the row (adding classes to the row for example).
_this.options.postAddRowHandler(row, rowData);
}
} }
//Setup the row selection handler. //Setup the row selection handler.
if(selection == 'row') table.on('click', 'tbody tr', clickHandler); if(selection == 'row') table.on('click', 'tbody tr', selectionHandler);
}); });
} }
}(jQuery); }(jQuery);

View File

@@ -50,16 +50,21 @@ $(document).ready(function($) {
(function(){ (function(){
var htmlOriginal = jQuery.fn.html; var htmlOriginal = jQuery.fn.html;
jQuery.fn.html = function(html) { jQuery.fn.html = function(html) {
var data = brainstormFramework.extractViewData(html); if(html != undefined) {
var data = brainstormFramework.extractViewData(html);
htmlOriginal.apply(this, [data.view]); htmlOriginal.apply(this, [data.view]);
if(data.script && data.script.length > 0) { if(data.script && data.script.length > 0) {
try { try {
eval(data.script); eval(data.script);
} catch(err) { } catch(err) {
alert(err); alert(err);
}
} }
} }
else {
htmlOriginal.apply(this, html);
}
} }
})(); })();

View File

@@ -398,6 +398,12 @@ sub {
.inlineBlock { .inlineBlock {
display: inline-block; display: inline-block;
} }
.modal-dialog {
background: #fff;
}
.selected {
background-color: #ffe184 !important;
}
/* Footer Lines */ /* Footer Lines */
#footer { #footer {
margin-top: 6px; margin-top: 6px;
@@ -497,6 +503,6 @@ sub {
.headerIcon { .headerIcon {
width: 30px; width: 30px;
} }
#users .highlight { #users .selected {
background-color: #ffe184 !important; background-color: #ffe184 !important;
} }

View File

@@ -420,6 +420,14 @@ sup, sub {
display: inline-block; display: inline-block;
} }
.modal-dialog {
background: white;
}
.selected {
background-color: #ffe184 !important;
}
/* Footer Lines */ /* Footer Lines */
#footer { #footer {
@@ -468,3 +476,8 @@ sup, sub {
@require "home" @require "home"
@require "editor" @require "editor"
@require "users" @require "users"
@require "venues"
@require "measures"
@require "categories"
@require "subcategories"
@require "items"

View File

@@ -0,0 +1,3 @@
#measures .selected {
background-color: #ffe184 !important;
}

195
public/admin/measures.html Normal file
View File

@@ -0,0 +1,195 @@
<div id="measures" class="page">
<div class="col-sm-12 col-sm-offset-0">
<h1><span class="fa fa-users"></span> Manage Measures</h1>
<div class="col-sm-6">
<div class="dt-buttons btn-group" style="display: inline-block">
<a id="createButton" class="btn btn-default buttons-create" tabindex="0" href="javaScript:void(0);"><span>New</span></a>
<a id="editButton" class="btn btn-default buttons-selected buttons-edit" tabindex="0" href="javaScript:void(0);"><span>Edit</span></a>
<a id="deleteButton" class="btn btn-default buttons-selected buttons-remove" tabindex="0" href="javaScript:void(0);"><span>Delete</span></a>
</div>
<div class="checkbox checkbox-slider checkbox-slider--b-flat" style="display: inline-block; margin-left: 20px">
<label>
<input type="checkbox" id="includeDeletedToggle"><span style="margin-left: 0; padding-left: 24px;">Include Deleted</span>
</label>
</div>
</div>
<table id="data-table" class="table table-striped table-hover">
<thead>
<tr>
<th data-key-name="name">Name</th>
<th data-key-name="postfix">Postfix</th>
</tr>
</thead>
</table>
<div id="createDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Create Measure</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" id="createDialog_NameField" tabindex="0">
</div>
<div class="form-group">
<label>Postfix</label>
<input type="text" class="form-control" name="postfix" id="createDialog_PostfixField" tabindex="0">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-md" id="createDialog_CreateButton" tabindex="0">Create</button>
<button type="button" class="btn" data-dismiss="modal" tabindex="0">Cancel</button>
</div>
</div>
</div>
<div id="editDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Edit Measure</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" id="editDialog_NameField" tabindex="0">
</div>
<div class="form-group">
<label>Postfix</label>
<input type="text" class="form-control" name="postfix" id="editDialog_PostfixField" tabindex="0">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-md" id="editDialog_SaveButton" tabindex="0">Save</button>
<button type="button" class="btn" data-dismiss="modal" tabindex="0">Cancel</button>
</div>
</div>
</div>
<div id="deleteDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Delete Measure</h4>
</div>
<div class="modal-body">
Are you certain you wish to delete the venue <span id="deleteDialog_NameField"></span>?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning btn-md" id="deleteDialog_DeleteButton" tabindex="0">Delete</button>
<button type="button" class="btn btn-default" data-dismiss="modal" tabindex="1">Cancel</button>
</div>
</div>
</div>
<script language="JavaScript" type="text/javascript">
$(function() {
//# sourceURL=measures.html
var dataTable = new LinkedTable($('#data-table'), {
url: "measures/list",
attr: "data-key-name",
selection: "row",
parameters: function() {
return {showDeleted: $('#includeDeletedToggle').is(":checked") ? true : false};
},
postAddRowHandler: function($row, dataObject) {
if(dataObject.deletedAt) {
$("td:first", $row).prepend("<span class='glyphicon glyphicon-remove-circle' style='margin-right: 10px;' aria-hidden='true'></span>");
}
}
});
//Call the refresh user table function once initially.
dataTable.refresh();
//---- Create Dialog ----
$("#createButton").on("click", function(event) {
$("#createDialog").modal();
});
$("#createDialog_CreateButton").on("click", function(event) {
try {
$.post("/admin/measures/create", {
name: $("#createDialog_NameField").val(),
postfix: $("#createDialog_PostfixField").val()
}, function(data) {
if(data.result == "success") {
$("#createDialog").modal("hide");
dataTable.refresh();
}
else {
alert(data.result);
}
}, "json");
} catch(e) {
alert(e);
}
});
$("#createDialog").on('shown.bs.modal', function() {
$('#createDialog_NameField').focus();
});
//----------------------------
//---- Delete Dialog ----
$("#deleteButton").on("click", function(event) {
//debugger;
if(dataTable.getSelectedRow() != null) {
$("#deleteDialog_NameField").html(dataTable.getSelectedRow().data("model").name);
$("#deleteDialog").modal();
}
});
$("#deleteDialog_DeleteButton").on("click", function(event) {
if(dataTable.getSelectedRow() != null) {
$.post("/admin/measures/delete", {id: dataTable.getSelectedRow().data("model").id}, function(data) {
if(data.result == "success") {
$("#deleteDialog").modal("hide");
dataTable.refresh();
}
else {
alert(data.result);
}
}, "json");
}
});
//-----------------------------
//----- Edit Dialog ----
$("#editButton").on("click", function(event) {
//debugger;
if(dataTable.getSelectedRow() != null) {
$('#editDialog_NameField').val(dataTable.getSelectedRow().data("model").name);
$('#editDialog_PostfixField').val(dataTable.getSelectedRow().data("model").postfix);
$("#editDialog").modal();
}
});
$("#editDialog_SaveButton").on("click", function(event) {
if(dataTable.getSelectedRow() != null) {
$.post("/admin/measures/edit", {
id: dataTable.getSelectedRow().data("model").id,
name: $("#editDialog_NameField").val(),
postfix: $("#createDialog_PostfixField").val()
}, function(data) {
if(data.result == "success") {
$("#editDialog").modal("hide");
dataTable.refresh();
}
else {
alert(data.result);
}
}, "json");
}
});
$("#editDialog").on('shown.bs.modal', function() {
$('#editDialog_NameField').focus().select();
});
//---------------------
$('#includeDeletedToggle').on('click', function(event) {
dataTable.refresh();
});
});
</script>
</div>
</div>

View File

@@ -0,0 +1,2 @@
#measures {
}

View File

View File

@@ -0,0 +1,183 @@
<div id="subcategories" class="page">
<div class="col-sm-12 col-sm-offset-0">
<h1><span class="fa fa-users"></span> Manage Subcategories</h1>
<div class="col-sm-6">
<div class="dt-buttons btn-group" style="display: inline-block">
<a id="createButton" class="btn btn-default buttons-create" tabindex="0" href="javaScript:void(0);"><span>New</span></a>
<a id="editButton" class="btn btn-default buttons-selected buttons-edit" tabindex="0" href="javaScript:void(0);"><span>Edit</span></a>
<a id="deleteButton" class="btn btn-default buttons-selected buttons-remove" tabindex="0" href="javaScript:void(0);"><span>Delete</span></a>
</div>
<div class="checkbox checkbox-slider checkbox-slider--b-flat" style="display: inline-block; margin-left: 20px">
<label>
<input type="checkbox" id="includeDeletedToggle"><span style="margin-left: 0; padding-left: 24px;">Include Deleted</span>
</label>
</div>
</div>
<table id="subcategory-table" class="table table-striped table-hover">
<thead>
<tr>
<th data-key-name="name">Name</th>
</tr>
</thead>
</table>
<div id="createDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Create Subcategory</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" id="createDialog_NameField" tabindex="0">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-md" id="createDialog_CreateButton" tabindex="0">Create</button>
<button type="button" class="btn" data-dismiss="modal" tabindex="0">Cancel</button>
</div>
</div>
</div>
<div id="editDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Edit Subcategory</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" id="editDialog_NameField" tabindex="0">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-md" id="editDialog_SaveButton" tabindex="0">Save</button>
<button type="button" class="btn" data-dismiss="modal" tabindex="0">Cancel</button>
</div>
</div>
</div>
<div id="deleteDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Delete Subcategory</h4>
</div>
<div class="modal-body">
Are you certain you wish to delete the subcategory <span id="deleteDialog_NameField"></span>?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning btn-md" id="deleteDialog_DeleteButton" tabindex="0">Delete</button>
<button type="button" class="btn btn-default" data-dismiss="modal" tabindex="1">Cancel</button>
</div>
</div>
</div>
<script language="JavaScript" type="text/javascript">
$(function() {
//# sourceURL=subcategories.html
var dataTable = new LinkedTable($('#subcategory-table'), {
url: "subcategories/list",
attr: "data-key-name",
selection: "row",
parameters: function() {
return {showDeleted: $('#includeDeletedToggle').is(":checked") ? true : false};
},
postAddRowHandler: function($row, dataObject) {
if(dataObject.deletedAt) {
$("td:first", $row).prepend("<span class='glyphicon glyphicon-remove-circle' style='margin-right: 10px;' aria-hidden='true'></span>");
}
}
});
//Call the refresh user table function once initially.
dataTable.refresh();
//---- Create Dialog ----
$("#createButton").on("click", function(event) {
$("#createDialog").modal();
});
$("#createDialog_CreateButton").on("click", function(event) {
try {
$.post("/admin/subcategories/create", {
name: $("#createDialog_NameField").val()
}, function(data) {
if(data.result == "success") {
$("#createDialog").modal("hide");
dataTable.refresh();
}
else {
alert(data.result);
}
}, "json");
} catch(e) {
alert(e);
}
});
$("#createDialog").on('shown.bs.modal', function() {
$('#createDialog_NameField').focus();
});
//----------------------------
//---- Delete Dialog ----
$("#deleteButton").on("click", function(event) {
//debugger;
if(dataTable.getSelectedRow() != null) {
$("#deleteDialog_NameField").html(dataTable.getSelectedRow().data("model").name);
$("#deleteDialog").modal();
}
});
$("#deleteDialog_DeleteButton").on("click", function(event) {
if(dataTable.getSelectedRow() != null) {
$.post("/admin/subcategories/delete", {id: dataTable.getSelectedRow().data("model").id}, function(data) {
if(data.result == "success") {
$("#deleteDialog").modal("hide");
dataTable.refresh();
}
else {
alert(data.result);
}
}, "json");
}
});
//-----------------------------
//----- Edit Dialog ----
$("#editButton").on("click", function(event) {
//debugger;
if(dataTable.getSelectedRow() != null) {
$('#editDialog_NameField').val(dataTable.getSelectedRow().data("model").name);
$("#editDialog").modal();
}
});
$("#editDialog_SaveButton").on("click", function(event) {
if(dataTable.getSelectedRow() != null) {
$.post("/admin/subcategories/edit", {
id: dataTable.getSelectedRow().data("model").id,
name: $("#editDialog_NameField").val()
}, function(data) {
if(data.result == "success") {
$("#editDialog").modal("hide");
dataTable.refresh();
}
else {
alert(data.result);
}
}, "json");
}
});
$("#editDialog").on('shown.bs.modal', function() {
$('#editDialog_NameField').focus().select();
});
//---------------------
$('#includeDeletedToggle').on('click', function(event) {
dataTable.refresh();
});
});
</script>
</div>
</div>

View File

@@ -0,0 +1,2 @@
#subcategories {
}

View File

@@ -5,8 +5,9 @@
<div class="col-sm-6"> <div class="col-sm-6">
<div class="dt-buttons btn-group"> <div class="dt-buttons btn-group">
<a id="createButton" class="btn btn-default buttons-create" tabindex="0" href="javaScript:void(0);"><span>New</span></a> <a id="createButton" class="btn btn-default buttons-create" tabindex="0" href="javaScript:void(0);"><span>New</span></a>
<a class="btn btn-default buttons-selected buttons-edit" tabindex="0" href="javaScript:void(0);"><span>Edit</span></a> <a id="changeLoginButton" class="btn btn-default buttons-selected buttons-edit" tabindex="0" href="javaScript:void(0);"><span>Change Login</span></a>
<a class="btn btn-default buttons-selected buttons-remove" tabindex="0" href="javaScript:void(0);"><span>Delete</span></a> <a id="resetPasswordButton" class="btn btn-default buttons-selected buttons-edit" tabindex="0" href="javaScript:void(0);"><span>Reset Password</span></a>
<a id="deleteButton" class="btn btn-default buttons-selected buttons-remove" tabindex="0" href="javaScript:void(0);"><span>Delete</span></a>
</div> </div>
</div> </div>
<table id="user-table" class="table table-striped table-hover"> <table id="user-table" class="table table-striped table-hover">
@@ -20,7 +21,6 @@
<div id="createUserDialog" class="modal fade" role="dialog"> <div id="createUserDialog" class="modal fade" role="dialog">
<div class="modal-dialog"> <div class="modal-dialog">
<!--<form action="/admin/createUser" method="post">-->
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button> <button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Create User</h4> <h4 class="modal-title">Create User</h4>
@@ -28,40 +28,193 @@
<div class="modal-body"> <div class="modal-body">
<div class="form-group"> <div class="form-group">
<label>Login</label> <label>Login</label>
<input type="text" class="form-control" name="login" id="loginDialogLogin"> <input type="text" class="form-control" name="login" id="loginDialogLogin" tabindex="0">
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Password</label> <label>Password</label>
<input type="password" class="form-control" name="password" id="loginDialogPassword"> <input type="password" class="form-control" name="password" id="loginDialogPassword" tabindex="0">
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-warning btn-md" id="createUserDialogButton">Create</button> <button type="button" class="btn btn-warning btn-md" id="createUserDialogButton" tabindex="0">Create</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-default" data-dismiss="modal" tabindex="0">Close</button>
</div> </div>
<!--</form>--> </div>
</div>
<div id="resetPasswordDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Reset Password</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" name="password" id="resetPasswordDialogPassword" tabindex="0">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning btn-md" id="resetPasswordDialogSaveButton" tabindex="0">Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal" tabindex="0">Cancel</button>
</div>
</div>
</div>
<div id="changeLoginDialog" class="modal fade" role="dialog">
<div id="changeLoginDialogInner" class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Change Login</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>Login</label>
<input type="text" class="form-control" name="password" id="changeLoginDialogLogin" tabindex="0">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning btn-md" id="changeLoginDialogSaveButton" tabindex="0">Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal" tabindex="0">Cancel</button>
</div>
</div>
</div>
<div id="deleteUserDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Delete User</h4>
</div>
<div class="modal-body">
Are you certain you wish to delete the user <span id="deleteUserDialogUserName"></span>?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning btn-md" id="deleteUserDialogDeleteButton" tabindex="0">Delete</button>
<button type="button" class="btn btn-default" data-dismiss="modal" tabindex="1">Cancel</button>
</div>
</div> </div>
</div> </div>
<script language="JavaScript" type="text/javascript"> <script language="JavaScript" type="text/javascript">
var userTable = new LinkedTable($('#user-table'), {url: "user-data", attr: "data-key-name", selection: "row"}); $(function() {
//# sourceURL=users.html
var userTable = new LinkedTable($('#user-table'), {
url: "user/list",
attr: "data-key-name",
selection: "row"
});
//Call the refresh user table function once initially. //Call the refresh user table function once initially.
userTable.refresh(); userTable.refresh();
$("#createButton").on("click", function(event) {
$("#createUserDialog").modal(); //---- Create User Dialog ----
$("#createButton").on("click", function(event) {
$("#createUserDialog").modal();
});
$("#createUserDialogButton").on("click", function(event) {
try {
$.post("/admin/user/create", {
login: $("#loginDialogLogin").val(),
password: $("#loginDialogPassword").val()
}, function(data) {
if(data.result == "success") {
$("#createUserDialog").modal("hide");
userTable.refresh();
}
else {
alert(data.result);
}
}, "json");
} catch(e) {
alert(e);
}
});
$("#createUserDialog").on('shown.bs.modal', function() {
$('#createUserDialogLogin').focus();
});
//----------------------------
//---- Delete User Dialog ----
$("#deleteButton").on("click", function(event) {
//debugger;
if(userTable.getSelectedRow() != null) {
//Note: This assumes that the first column is the user login (name).
//$("#deleteUserDialogUserName").html($("td", userTable.getSelectedRow())[0].innerHTML);
$("#deleteUserDialogUserName").html(userTable.getSelectedRow().data("model").login);
$("#deleteUserDialog").modal();
}
});
$("#deleteUserDialogDeleteButton").on("click", function(event) {
if(userTable.getSelectedRow() != null) {
$.post("/admin/user/delete", {id: userTable.getSelectedRow().data("model").id}, function(data) {
if(data.result == "success") {
$("#deleteUserDialog").modal("hide");
userTable.refresh();
}
else {
alert(data.result);
}
}, "json");
}
});
//-----------------------------
//----- Change Login Dialog ----
$("#changeLoginButton").on("click", function(event) {
if(userTable.getSelectedRow() != null) {
$('#changeLoginDialogLogin').val(userTable.getSelectedRow().data("model").login);
$("#changeLoginDialog").modal();
}
});
$("#changeLoginDialogSaveButton").on("click", function(event) {
if(userTable.getSelectedRow() != null) {
$.post("/admin/user/changeLogin", {
id: userTable.getSelectedRow().data("model").id,
login: $("#changeLoginDialogLogin").val()
}, function(data) {
if(data.result == "success") {
$("#changeLoginDialog").modal("hide");
userTable.refresh();
}
else {
alert(data.result);
}
}, "json");
}
});
$("#changeLoginDialog").on('shown.bs.modal', function() {
$('#changeLoginDialogLogin').focus().select();
});
//---------------------
//---- Reset Password Dialog ----
$("#resetPasswordButton").on("click", function(event) {
if(userTable.getSelectedRow() != null) {
$("#resetPasswordDialog").modal();
}
});
$("#resetPasswordDialogSaveButton").on("click", function(event) {
if(userTable.getSelectedRow() != null) {
$.post("/admin/user/resetPassword", {
id: userTable.getSelectedRow().data("model").id,
password: $("#resetPasswordDialogPassword").val()
}, function(data) {
if(data.result == "success") {
$("#resetPasswordDialog").modal("hide");
userTable.refresh();
}
else {
alert(data.result);
}
}, "json");
}
});
$("#resetPasswordDialog").on('shown.bs.modal', function() {
$('#resetPasswordDialogPassword').focus();
});
//----------------------------------
}); });
$("#createUserDialogButton").on("click", function(event) {
$.post("createUser", {login: $("#loginDialogLogin"), password: $("#loginDialogPassword")}, function(data) {
if(data.result == "success") {
}
else {
alert(data.result);
}
}, "json");
})
</script> </script>
</div> </div>
</div> </div>

View File

@@ -1,5 +1,5 @@
#users { #users {
.highlight { .selected {
background-color: #ffe184 !important; background-color: #ffe184 !important;
} }
} }

2
public/admin/venues.styl Normal file
View File

@@ -0,0 +1,2 @@
#venues {
}