Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Modularize! #56

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 1 addition & 158 deletions oratory/www/modules/app.dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,6 @@ define(['angular', 'moment', 'socket', 'jquery', 'underscore'], function (angula
};
},

listAttachment: function (master) {
return {
restrict: 'E',
scope: {
attachment: '=',
editAttachment: '='
},
templateUrl: 'html/listAttachment.html',
link: function (scope) {
scope.colors = master.color(scope.attachment);
}
};
},

imageSearch: function ($http) {
return {
restrict: 'E',
Expand Down Expand Up @@ -611,150 +597,7 @@ define(['angular', 'moment', 'socket', 'jquery', 'underscore'], function (angula

}
};
},

listBudget: function (master) {
return {
restrict: 'E',
scope: {
budget: '=',
item: '=',
editBudget: '='
},
templateUrl: 'html/listBudget.html',
link: function (scope) {
scope.dbInfo = master.getDbInfo;
scope.sharedData = master.sharedData;
if (!scope.budget) {
scope.budget = {};
}
scope.budget.total = 0;

scope.newLine = {};

if (scope.editBudget) {
if (!scope.budget) {
scope.budget = {};
scope.budget.lines = [];
if (scope.item.attachments) {
//loop throught and add
_(scope.item.attachments).each(function (uid) {
var attachment = _(master.items).findWhere({uid: uid});
if (attachment.need === 'want') {
scope.budget.lines.push({name: attachment.name, price: attachment.price});
}
});
}
}
}

scope.getTotal = function () {
var total = 0;
if (!scope.budget.lines) {
scope.budget.lines = [];
}
_.forEach(scope.budget.lines, function (line) {
if ($.isNumeric(line.price)) {
total = total + Number(line.price);
}
});
scope.budget.total = total;
};
scope.getTotal();

scope.isNumber = function () {
if (!$.isNumeric(scope.newLine.price)) {
scope.newLine.price = 0;
}
};

scope.saveBudget = function () {
scope.item.budget = scope.budget;
master.saveItem(scope.item);
scope.$emit('closeBudget');
};

scope.addLine = function () {
scope.budget.lines.push(scope.newLine);
scope.getTotal();
scope.newLine = {};
};

scope.removeLine = function (index) {
scope.budget.lines.splice(index, 1);
scope.getTotal();
};
}
};
},

listResult: function ($state, $http) {
return {
restrict: 'E',
scope: {
proposal: '=',
result: '=',
key: '='
},
templateUrl: 'html/listResult.html',
link: function (scope) {
scope.saveResult = function () {
delete scope.result.edit;
scope.proposal[scope.result.who] = scope.result;
var pushComponents = {};
pushComponents.uid = scope.proposal.uid;
pushComponents.who = scope.result.who;
pushComponents[scope.result.who] = scope.result;
pushComponents.key = scope.key;
$http.post('/api/proposalResult', pushComponents).then(function () {
$state.go('proposal/:uid/:resultee', {uid: scope.proposal.uid, resultee: ''});
});
};
}
};
},


addMediaImageForm: function () {
return {
restrict: 'E',
scope: {
mediaImage: '='
},
templateUrl: 'html/addMediaImageForm.html',
link: function (scope, element) {
var takePicture = element.find(".take-picture");
var showPicture = element.find(".show-picture");

if (takePicture && showPicture) {
// Set events
takePicture.on('change', function (event) {

// Get a reference to the taken picture or chosen file
var files = event.target.files;
var file;
if (files && files.length > 0) {
file = files[0];

try {
var fileReader = new FileReader();
fileReader.onload = function (event) {
scope.mediaImage = event.target.result;
scope.$digest();
};
fileReader.readAsDataURL(file);
} catch (e) {
// Display error message
scope.errorMsg = 'nothing is supported';
}
}

});//END take picture 'on' event
}


}//link
};
}

};
});
36 changes: 36 additions & 0 deletions www/modules/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*jslint browser:true */
/*global define */

define([
'angular',
'app.svc',
'app.ctrl',
'app.config',
'app.dir',
'toolbar/dir',
'owners/edit/dir',
'mediaImages/edit/dir',
'budget/list/dir',
'attachments/edit/dir',
'result/list/dir',
'app.filter',
'angular-ui-router'
], function (angular,
appSvc, appCtrl, appCfg, appDir, appDirToolbar, appDirEditOwners, appDirEditMediaImages,
budgetList, appDirEditAttachments, appDirListResult, appFilt) {
'use strict';

return angular.module('app', ['ui.router'])
.factory(appSvc)
.controller(appCtrl)
.config(appCfg)
.directive(appDir)
//modules
.directive(appDirToolbar)
.directive(appDirEditOwners)
.directive(appDirEditMediaImages)
.directive(budgetList)
.directive(appDirEditAttachments)
.directive(appDirListResult)
.filter(appFilt);
});
22 changes: 22 additions & 0 deletions www/modules/attachments/edit/dir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*jslint browser:true, nomen:true, vars:true */
/*global define, FileReader */

define([], function () {
'use strict';

return {
editAttachment: function (master) {
return {
restrict: 'E',
scope: {
attachment: '=',
editAttachment: '='
},
templateUrl: 'modules/attachments/edit/template.html',
link: function (scope) {
scope.colors = master.color(scope.attachment);
}
};
}
};
});
83 changes: 83 additions & 0 deletions www/modules/budget/list/dir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*jslint browser:true, nomen:true, vars:true */
/*global define, FileReader */

define(['underscore', 'jquery'], function (_, $) {
'use strict';

return {
listBudget: function (master) {
return {
restrict: 'E',
scope: {
budget: '=',
item: '=',
editBudget: '='
},
templateUrl: 'modules/budget/list/template.html',
link: function (scope) {
scope.dbInfo = master.getDbInfo;
scope.sharedData = master.sharedData;
if (!scope.budget) {
scope.budget = {};
}
scope.budget.total = 0;

scope.newLine = {};

if (scope.editBudget) {
if (!scope.budget) {
scope.budget = {};
scope.budget.lines = [];
if (scope.item.attachments) {
//loop throught and add
_(scope.item.attachments).each(function (uid) {
var attachment = _(master.items).findWhere({uid: uid});
if (attachment.need === 'want') {
scope.budget.lines.push({name: attachment.name, price: attachment.price});
}
});
}
}
}

scope.getTotal = function () {
var total = 0;
if (!scope.budget.lines) {
scope.budget.lines = [];
}
_.forEach(scope.budget.lines, function (line) {
if ($.isNumeric(line.price)) {
total = total + Number(line.price);
}
});
scope.budget.total = total;
};
scope.getTotal();

scope.isNumber = function () {
if (!$.isNumeric(scope.newLine.price)) {
scope.newLine.price = 0;
}
};

scope.saveBudget = function () {
scope.item.budget = scope.budget;
master.saveItem(scope.item);
scope.$emit('closeBudget');
};

scope.addLine = function () {
scope.budget.lines.push(scope.newLine);
scope.getTotal();
scope.newLine = {};
};

scope.removeLine = function (index) {
scope.budget.lines.splice(index, 1);
scope.getTotal();
};
}
};
}
};
});
52 changes: 52 additions & 0 deletions www/modules/budget/list/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<table class="table">
<tr ng-repeat="line in budget.lines" class="row">
<td style="width:40px;">
<span class="pad-left">{{$index+1}}.</span>
</td>
<td>
<span ng-if="!editBudget">{{line.name}}</span>
<input ng-if="editBudget" class="form-control" type="text" ng-model="budget.lines[$index].name" placeholder="name"/>
</td>
<td>
<span ng-if="!editBudget">{{line.price}}</span>
<input ng-if="editBudget" class="form-control" type="text" ng-change="getTotal()" ng-model="budget.lines[$index].price" placeholder="price"/>
</td>
<td>
<span ng-if="!editBudget">{{line.comment}}</span>
<input ng-if="editBudget" class="form-control" type="text" ng-model="budget.lines[$index].comment" placeholder="comment"/>
</td>
<td>
<button ng-if="editBudget" class="btn btn-xs btn-default" ng-click="removeLine($index)">remove</button>
</td>

</tr>
<tr ng-if="editBudget" class="row">
<td>
<span>add:</span>
</td>
<td>
<input class="form-control" type="text" ng-model="newLine.name" placeholder="name"/>
</td>
<td>
<input class="form-control" type="text" ng-model="newLine.price" ng-change="isNumber()" placeholder="price"/>
</td>
<td>
<input class="form-control" type="text" ng-model="newLine.comment" placeholder="comment"/>
</td>
<td>
<button class="btn btn-xs btn-default" ng-click="addLine()">add</button>
</td>
</tr>
<tr class="row">
<td></td>
<td style="text-align:right;">
<span style="font-weight:bold;">total:</span>
</td>
<td>
<span style="font-weight:bold;">{{budget.total}}</span>
</td>
<td></td>
<td></td>
</tr>
</table>
<button ng-if="editBudget" class="btn btn-default" ng-click="saveBudget()">save budget</button>
Loading