Created
May 21, 2015 15:51
-
-
Save zxqx/10463c651a0f50293a8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import angular from 'angular'; | |
import widgetEvents from './widget-events'; | |
/** | |
* Handle the creation workflow of a new content capsule | |
*/ | |
export default class CapsuleEdit { | |
constructor($scope, widgetManager, $upload, $stateParams, ContentCapsuleAdmin) { | |
this.$scope = $scope; | |
this.widgetManager = widgetManager; | |
this.ContentCapsuleAdmin = ContentCapsuleAdmin; | |
this.$scope.settings = this.$scope.settings || { }; | |
this.agencyId = $stateParams.agency; | |
this.clientId = $stateParams.client; | |
this.capsuleId = $stateParams.capsule; | |
this.capsule = null; | |
// Load the capsule | |
this.loadCapsule(this.agencyId, this.clientId, this.capsuleId); | |
this.$scope.saving = false; | |
} | |
/** | |
* Load the model for the content capsule | |
*/ | |
async loadCapsule(agencyId, clientId, capsuleId) { | |
// Extend the settings to this | |
this.$scope.settings = await this.ContentCapsuleAdmin.fetchCapsule(agencyId, clientId, capsuleId); | |
console.log("Loaded Capsule", this.$scope.settings); | |
// set the active page to the first page that will be in the tab | |
this.$scope.activePage = this.$scope.settings.pages[0]; | |
} | |
async createWidget(widgetData: object) { | |
this.$scope.saving = true; | |
let widget = await this.widgetManager.create(widgetData); | |
this.$scope.saving = false; | |
this.$scope.settings.widgets.push(widget); | |
this.$scope.$broadcast(widgetEvents.ADDED); | |
} | |
selectTemplate(templateKey: String) { | |
this.$scope.activePage.referenceId = templateKey; | |
} | |
assignWidgetToRegion(widget: object, regionId: number) { | |
this.$scope.activePage.regions[regionId] = widget; | |
this.$scope.$broadcast(widgetEvents.ASSIGNED, { | |
page: this.$scope.activePage, | |
regionId: regionId, | |
widget: widget | |
}); | |
} | |
editWidget(type: string, scope: object) { | |
return this.widgetManager.renderEditForm(type, scope); | |
} | |
renderWidget(widget) { | |
return this.widgetManager.render(widget); | |
} | |
addPage() { | |
this.$scope.settings.addPage('Page', 'Extra Page'); | |
} | |
selectPage(page:Object) { | |
this.$scope.activePage = page; | |
} | |
/** | |
* Save this version of the content capsule | |
* @type {[type]} | |
*/ | |
async save(message:String) { | |
this.$scope.saving = true; | |
await this.$scope.settings.save(); | |
this.$scope.saving = false; | |
} | |
async delete() { | |
this.$scope.settings.delete(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment