Working on adding support for template file attachments

pull/24/head
Jordan 2014-07-12 13:46:38 -05:00
parent 7e87980fd7
commit 83ab6ffb52
6 changed files with 72 additions and 23 deletions

8
models/attachment.go Normal file
View File

@ -0,0 +1,8 @@
package models
type Attachment struct {
TemplateId string `json:"-"`
Content string `json:"content"`
Type string `json:"type"`
Name string `json:"name"`
}

View File

@ -61,6 +61,7 @@ func Setup() error {
db.CreateTable(Group{})
db.CreateTable(GroupTarget{})
db.CreateTable(Template{})
db.CreateTable(Attachment{})
db.CreateTable(SMTP{})
db.CreateTable(Event{})
db.CreateTable(Campaign{})

View File

@ -6,13 +6,14 @@ import (
)
type Template struct {
Id int64 `json:"id"`
UserId int64 `json:"-"`
Name string `json:"name"`
Subject string `json:"subject"`
Text string `json:"text"`
HTML string `json:"html"`
ModifiedDate time.Time `json:"modified_date"`
Id int64 `json:"id"`
UserId int64 `json:"-"`
Name string `json:"name"`
Subject string `json:"subject"`
Text string `json:"text"`
HTML string `json:"html"`
ModifiedDate time.Time `json:"modified_date"`
Attachments []Attachment `json:"attachments"`
}
var ErrTemplateNameNotSpecified = errors.New("Template Name not specified")
@ -28,11 +29,6 @@ func (t *Template) Validate() error {
return nil
}
type UserTemplate struct {
UserId int64 `json:"-"`
TemplateId int64 `json:"-"`
}
// GetTemplates returns the templates owned by the given user.
func GetTemplates(uid int64) ([]Template, error) {
ts := []Template{}
@ -41,6 +37,13 @@ func GetTemplates(uid int64) ([]Template, error) {
Logger.Println(err)
return ts, err
}
for i, _ := range ts {
err = db.Where("template_id=?", ts[i].Id).Find(&ts[i].Attachments).Error
if err != nil {
Logger.Println(err)
return ts, err
}
}
return ts, err
}
@ -52,6 +55,11 @@ func GetTemplate(id int64, uid int64) (Template, error) {
Logger.Println(err)
return t, err
}
err = db.Where("template_id=?", t.Id).Find(&t.Attachments).Error
if err != nil {
Logger.Println(err)
return t, err
}
return t, err
}
@ -80,8 +88,7 @@ func PostTemplate(t *Template) error {
// PutTemplate edits an existing template in the database.
// Per the PUT Method RFC, it presumes all data for a template is provided.
func PutTemplate(t *Template) error {
Logger.Println(t)
err := db.Debug().Where("id=?", t.Id).Save(t).Error
err := db.Where("id=?", t.Id).Save(t).Error
if err != nil {
Logger.Println(err)
return err

View File

@ -35,6 +35,15 @@ app.config(function($routeProvider) {
})
});
app.config( [
'$compileProvider',
function( $compileProvider )
{
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|data):/);
// Angular before v1.2 uses $compileProvider.urlSanitizationWhitelist(...)
}
]);
app.filter('cut', function() {
return function(value, max, tail) {
if (!value) return '';

View File

@ -18,7 +18,7 @@ app.controller('DashboardCtrl', function($scope, $filter, $location, CampaignSer
campaign.x = new Date(campaign.created_date)
campaign.y = 0
angular.forEach(campaign.results, function(result, r_key) {
if (result.status == "Clicked Link") {
if (result.status == "Success") {
campaign.y++;
}
})
@ -600,6 +600,7 @@ app.controller('TemplateCtrl', function($scope, $modal, TemplateService, ngTable
name: '',
html: '',
text: '',
files: []
};
} else {
@ -652,7 +653,24 @@ app.controller('TemplateCtrl', function($scope, $modal, TemplateService, ngTable
}
})
var TemplateModalCtrl = function($scope, $modalInstance) {
var TemplateModalCtrl = function($scope, $upload, $modalInstance) {
var reader = new FileReader();
$scope.onFileSelect = function($files) {
angular.forEach($files, function(file, key) {
reader.onload = function(e) {
$scope.template.files.push({
name : file.name,
content : reader.result.split(",")[1],
type : file.type || "application/octet-stream"
})
$scope.$apply();
}
reader.onerror = function(e) {
console.log(e)
}
reader.readAsDataURL(file)
})
}
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};

View File

@ -11,7 +11,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" ng-model="template.subject" placeholder="Email Subject" id="subject" />
</div>
<fieldset disabled>
<div class="form-group">
@ -30,12 +30,18 @@
<div ng-model="template.html" contenteditable></div>
</tab>
</tabset>
<fieldset disabled>
<div class="form-group" style="margin-top:15px">
<button class="btn btn-danger btn-disabled"><i class="fa fa-plus"></i> Add Files (Coming Soon!)</button>
</div>
</fieldset>
<br />
<span class="btn btn-danger btn-file"><i class="fa fa-plus"></i> Add Files (Coming Soon!)
<input type="file" ng-file-select="onFileSelect($files)">
</span>
<div ng-repeat="file in template.files" ng-model="template.files">
<i class="fa fa-file-excel-o" ng-show="file.type == 'application/vnd.ms-excel'"></i>
<i class="fa fa-file-text-o" ng-show="file.type == 'text/plain'"></i>
<i class="fa fa-file-image-o" ng-show="file.type == 'image/gif'"></i>
<i class="fa fa-file" ng-show="file.type == 'application/octet-stream'"></i>
&nbsp;{{file.name}}
{{file.type}}
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="cancel()">Cancel</button>