Can now create templates (working on edit functionality for all of these)

pull/24/head
unknown 2015-06-29 19:33:11 -05:00
parent 62323c170e
commit 1d0636daab
4 changed files with 33 additions and 17 deletions

3
static/css/main.css vendored
View File

@ -1,5 +1,8 @@
.nav-tabs {
cursor:pointer;
}
.datatable_hidden {
display:none;
}
.navbar-logo {
margin: 4px 0px;

View File

@ -38,6 +38,7 @@
<th></th>
<th>Name</th>
<th></th>
<th>Content</th>
</tr>
</thead>
<tbody>

View File

@ -16,7 +16,17 @@ var icons = {
// Save attempts to POST to /templates/
function save(){
template.name = $("#name").val()
console.log(template)
template.subject = $("#subject").val()
template.html = CKEDITOR.instances["html_editor"].getData();
template.text = $("#text_editor").val()
// Add the attachments
$.each($("#attachmentsTable").DataTable().rows().data(), function(i, target){
template.attachments.push({
name : target[1],
content: target[3],
type: target[4],
})
})
// Submit the template
api.templates.post(template)
.success(function(data){
@ -25,8 +35,7 @@ function save(){
dismiss()
})
.error(function(data){
$("#modal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
<i class=\"fa fa-exclamation-circle\"></i> " + data.responseJSON.message + "</div>")
modalError(data.responseJSON.message)
})
}
@ -42,18 +51,14 @@ function attach(files){
var reader = new FileReader();
/* Make this a datatable */
reader.onload = function(e){
// Add the attachment
template.attachments.push({
name: file.name,
content: reader.result.split(",")[1],
type: file.type || "application/octet-stream"
})
var icon = icons[file.type] || "fa-file-o"
// Add the record to the modal
attachmentsTable.row.add([
'<i class="fa ' + icon + '"></i>',
file.name,
'<span class="remove-row"><i class="fa fa-trash-o"></i></span>'
'<span class="remove-row"><i class="fa fa-trash-o"></i></span>',
reader.result.split(",")[1],
file.type || "application/octet-stream"
]).draw()
}
reader.onerror = function(e) {
@ -66,7 +71,12 @@ function attach(files){
function edit(t){
$("#html_editor").ckeditor()
$("#attachmentsTable").show()
$("#attachmentsTable").dataTable();
$("#attachmentsTable").DataTable({
"aoColumnDefs" : [{
"targets" : [3,4],
"sClass" : "datatable_hidden"
}]
});
if (t == "new") {
template = {attachments:[]}
}
@ -82,7 +92,7 @@ function load(){
$.each(templates, function(i, template){
templateTable.row.add([
template.name,
template.modified_date
moment(template.modified_date).format('MMMM Do YYYY, h:mm:ss a')
]).draw()
})
}

View File

@ -94,7 +94,7 @@
</div>
<label class="control-label" for="subject">Subject:</label>
<div class="form-group">
<input type="text" class="form-control" ng-model="template.subject" placeholder="Email Subject" id="subject" />
<input type="text" class="form-control" placeholder="Email Subject" id="subject" />
</div>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
@ -104,7 +104,7 @@
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="text">
<textarea rows="10" class="form-control" placeholder="Plaintext"></textarea>
<textarea rows="10" id="text_editor" class="form-control" placeholder="Plaintext"></textarea>
</div>
<div role="tabpanel" class="tab-pane" id="html">
<textarea id="html_editor"></textarea>
@ -122,6 +122,8 @@
<th class="col-md-1"></th>
<th class="col-md-10">Name</th>
<th class="col-md-1"></th>
<th class="datatable_hidden">Content</th>
<th class="datatable_hidden">Type</th>
</tr>
</thead>
<tbody>
@ -130,7 +132,7 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" onclick="dismiss()">Cancel</button>
<button type="button" class="btn btn-primary" onclick="save()" data-dismiss="modal">Save Template</button>
<button type="button" class="btn btn-primary" onclick="save()">Save Template</button>
</div>
</div>
</div>