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 { .nav-tabs {
cursor:pointer; cursor:pointer;
}
.datatable_hidden {
display:none;
} }
.navbar-logo { .navbar-logo {
margin: 4px 0px; margin: 4px 0px;

View File

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

View File

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

View File

@ -94,7 +94,7 @@
</div> </div>
<label class="control-label" for="subject">Subject:</label> <label class="control-label" for="subject">Subject:</label>
<div class="form-group"> <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> </div>
<!-- Nav tabs --> <!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist"> <ul class="nav nav-tabs" role="tablist">
@ -104,7 +104,7 @@
<!-- Tab panes --> <!-- Tab panes -->
<div class="tab-content"> <div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="text"> <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>
<div role="tabpanel" class="tab-pane" id="html"> <div role="tabpanel" class="tab-pane" id="html">
<textarea id="html_editor"></textarea> <textarea id="html_editor"></textarea>
@ -122,6 +122,8 @@
<th class="col-md-1"></th> <th class="col-md-1"></th>
<th class="col-md-10">Name</th> <th class="col-md-10">Name</th>
<th class="col-md-1"></th> <th class="col-md-1"></th>
<th class="datatable_hidden">Content</th>
<th class="datatable_hidden">Type</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -130,7 +132,7 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-default" onclick="dismiss()">Cancel</button> <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> </div>
</div> </div>