Skip to content
This repository has been archived by the owner on Apr 6, 2018. It is now read-only.

Commit

Permalink
Merge pull request #21 from AgronKabashi/Bug-fixes
Browse files Browse the repository at this point in the history
Minor Refactoring
  • Loading branch information
AgronKabashi committed Oct 27, 2014
2 parents 1b32a73 + 482025a commit 4762736
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 69 deletions.
1 change: 0 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
{
template = new Cerberus.Tool.TemplateEngine.Model.Template();
template.Name = "Template";
template.Resolutions.push(new Cerberus.Tool.TemplateEngine.Model.Resolution());
}

TemplateService.SaveTemplate(template)
Expand Down
2 changes: 1 addition & 1 deletion src/TemplateEditor/Controller/ContentEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
DataBagService.AddData("TemplateMode", TemplateMode.EditContent);
DataBagService.AddData("Template", TemplateEngineService.GetDocument(templateId, documentId, documentTypeId));

$scope.Save = function (successCallback)
$scope.Save = function ()
{
return TemplateEngineService.SaveDocument(DataBagService.GetData("Template"),
documentId,
Expand Down
54 changes: 0 additions & 54 deletions src/TemplateEditor/Dependencies/angularJS/HttpPost.js

This file was deleted.

60 changes: 47 additions & 13 deletions src/TemplateEngine/Service/TemplateLocalStorageProvider.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
define(
[
"angular"
"angular",
"lodash"
],
function (angular)
function (angular, lodash)
{
namespace("Cerberus.Tool.TemplateEngine.Service").TemplateLocalStorageProvider = angular.extend(function ($q)
{
var repository;
function updateLocalStorage()
var repository = JSON.parse(localStorage.getItem("TemplateRepository")) || { Templates: {} };

function UpdateLocalStorage()
{
localStorage.setItem("TemplateRepository", JSON.stringify(repository));
}

this.Configure = function (data) { };
function GenerateId()
{
return ~~lodash.max(repository.Templates, function (template)
{
return template.Id;
}).Id + 1;
}

repository = JSON.parse(localStorage.getItem("TemplateRepository")) || { Templates: {} };
this.Configure = function (data) { };

this.GetTemplate = function (templateId, documentId, documentTypeId)
{
Expand All @@ -24,7 +32,7 @@
this.RemoveTemplate = function (templateId)
{
delete repository.Templates[templateId];
updateLocalStorage();
UpdateLocalStorage();

return $q.when(true);
};
Expand All @@ -36,10 +44,8 @@
{
if (template.Id <= 0)
{
template.Id = ~~_.max(repository.Templates, function (template)
{
return template.Id;
}).Id + 1;
template.Id = GenerateId();
template.Resolutions.push(new Cerberus.Tool.TemplateEngine.Model.Resolution());
}

repository.Templates[template.Id] = template;
Expand Down Expand Up @@ -71,14 +77,22 @@
});
});

updateLocalStorage();
UpdateLocalStorage();

return template;
});
};

this.CloneTemplate = function (templateId, successCallback, errorCallback)
this.CloneTemplate = function (templateId)
{
var template = angular.extend({}, repository.Templates[templateId]);
template.Id = GenerateId();

repository.Templates[template.Id] = template;

UpdateLocalStorage();

return $q.when(template);
};

this.GetTemplates = function ()
Expand All @@ -98,7 +112,27 @@

this.SaveTemplateInfo = function (template)
{
return $q.when(template)
.then(function(template)
{
if (template.Id > 0)
{
var repoTemplate = repository.Templates[template.Id];
template.TemplateControls = repoTemplate.TemplateControls;
template.Resolutions = repoTemplate.Resolutions;
}
else
{
template.Id = GenerateId();
template.Resolutions.push(new Cerberus.Tool.TemplateEngine.Model.Resolution());
}

repository.Templates[template.Id] = template;

UpdateLocalStorage();

return template;
});
};

//TemplateContent
Expand Down

0 comments on commit 4762736

Please sign in to comment.