sheercms
Version:
Sheer Cliff CMS is a simple and powerful content management system (CMS) for Node JS.
326 lines (303 loc) • 9.19 kB
JavaScript
app.service('DialogService', function($q, $http, $modal) {
var self = this;
/*
branch: content, media, system
title: the title of the dialog
multiple: false
statuses: NSMPD
selectedIds: [] the item IDs to pre-select
onLoadItems: (items)
onSuccess: (value)
onCancel: ()
*/
self.openItemSelector = function(options) {
//set some defaults
var settings = {
branch: 'content',
multiple: false,
title: 'Item Selector',
statuses: 'NSMP',
selectedIds: [],
groups: null, // []
onLoadItems: function() {},
onSuccess: function() {},
onCancel: function() {}
};
angular.extend(settings, options);
var modalInstance = $modal.open({
templateUrl: 'ItemSelectorDialog',
controller: ItemSelectorController,
windowClass: 'xlarge-dialog',
resolve: {
branch: function() {
return settings.branch;
},
multiple: function() {
return settings.multiple;
},
title: function() {
return settings.title;
},
statuses: function() {
return settings.statuses;
},
selectedIds: function() {
return settings.selectedIds;
},
groups: function() {
return settings.groups;
},
onLoadItems: function() {
return settings.onLoadItems;
}
}
});
modalInstance.result.then(function (value) {
if (settings.onSuccess) {
settings.onSuccess(value);
}
}, function () {
if (settings.onCancel) {
settings.onCancel();
}
});
};
/*
title: the title of the dialog
value: the existing value
statuses: NSMPD
onLoadItems: (items)
onSuccess: (value)
onCancel: ()
*/
self.openLinkSelector = function(options) {
//set some defaults
var settings = {
title: 'Link Selector',
statuses: 'NSMP',
groups: null, // []
onLoadItems: function() {},
onSuccess: function() {},
onCancel: function() {}
};
angular.extend(settings, options);
var modalInstance = $modal.open({
templateUrl: 'LinkSelectorDialog',
controller: LinkSelectorController,
windowClass: 'xlarge-dialog',
resolve: {
title: function() {
return settings.title;
},
statuses: function() {
return settings.statuses;
},
onLoadItems: function() {
return settings.onLoadItems;
},
value: function() {
return settings.value;
},
groups: function() {
return settings.groups;
}
}
});
modalInstance.result.then(function (value) {
if (settings.onSuccess) {
settings.onSuccess(value);
}
}, function () {
if (settings.onCancel) {
settings.onCancel();
}
});
};
/*
title: the title of the dialog
groupId: the ID of the item group to upload to
onClose: (uploadCount)
*/
self.openUploadMedia = function(options) {
//set some defaults
var settings = {
title: 'Upload Media',
onClose: function() {}
};
angular.extend(settings, options);
var modalInstance = $modal.open({
templateUrl: 'UploadMediaDialog',
controller: UploadMediaDialogController,
windowClass: 'large-dialog',
resolve: {
title: function() {
return settings.title;
},
groupId: function() {
return settings.groupId;
},
onClose: function() {
return settings.onClose;
}
}
});
modalInstance.result.then(function (value) {
if (settings.onClose) {
settings.onClose(value);
}
}, function () {
if (settings.onClose) {
settings.onClose(null);
}
});
};
/*
onFiles: (files)
*/
self.showFileSelector = function(onFiles) {
var fileSelector = $('<input type="file" />');
fileSelector.on("change", function(evt) {
var files = evt.target.files;
if (onFiles)
onFiles(files);
});
fileSelector.click();
};
/*
title: the title of the dialog
value: the existing value
statuses: NSMPD
onLoadItems: (items)
onSuccess: (value)
onCancel: ()
*/
self.openImageSelector = function(options) {
//set some defaults
var settings = {
title: 'Image Selector',
statuses: 'NSMP',
groups: null, // []
onLoadItems: function() {},
onSuccess: function() {},
onCancel: function() {}
};
angular.extend(settings, options);
var modalInstance = $modal.open({
templateUrl: 'ImageSelectorDialog',
controller: ImageSelectorController,
windowClass: 'xlarge-dialog',
resolve: {
value: function() {
return settings.value;
},
title: function() {
return settings.title;
},
statuses: function() {
return settings.statuses;
},
groups: function() {
return settings.groups;
},
onLoadItems: function() {
return settings.onLoadItems;
}
}
});
modalInstance.result.then(function (value) {
if (settings.onSuccess) {
settings.onSuccess(value);
}
}, function () {
if (settings.onCancel) {
settings.onCancel();
}
});
};
self.openRawValue = function(rawValue, onClose) {
var modalInstance = $modal.open({
templateUrl: 'RawValueDialog',
controller: RawValueDialogController,
resolve: {
rawValue: function () {
return rawValue;
}
}
});
modalInstance.result.then(function(value) {
if (onClose)
onClose(value);
}, function() {
//cancelled
if (onClose)
onClose(null);
});
};
/*
title: the title of the dialog
value: the existing value
onSuccess: (value)
onCancel: ()
*/
self.openIconSelector = function(options) {
//set some defaults
var settings = {
title: 'Icon Selector',
onSuccess: function() {},
onCancel: function() {}
};
angular.extend(settings, options);
var modalInstance = $modal.open({
templateUrl: 'IconSelectorDialog',
controller: IconSelectorController,
windowClass: 'xlarge-dialog',
resolve: {
title: function() {
return settings.title;
},
value: function() {
return settings.value;
}
}
});
modalInstance.result.then(function (value) {
if (settings.onSuccess) {
settings.onSuccess(value);
}
}, function () {
if (settings.onCancel) {
settings.onCancel();
}
});
};
/*
branch: content, media, system
title: the title of the dialog
onSuccess: function(group)
onCancel: function()
*/
self.openGroupSelector = function(branch, title, onSuccess, onCancel) {
var modalInstance = $modal.open({
templateUrl: 'GroupSelectorDialog',
controller: GroupSelectorDialogController,
windowClass: 'medium-dialog',
resolve: {
branch: function() {
return branch;
},
title: function() {
return title;
}
}
});
modalInstance.result.then(function (value) {
if (onSuccess) {
onSuccess(value);
}
}, function () {
if (onCancel) {
onCancel();
}
});
};
});