Skip to content

Instantly share code, notes, and snippets.

@matijagrcic
Last active February 12, 2016 00:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matijagrcic/065862ca37b8b2fcd0ff to your computer and use it in GitHub Desktop.
Save matijagrcic/065862ca37b8b2fcd0ff to your computer and use it in GitHub Desktop.
module tweak {
function getViewUrl(viewName: string) {
return `/App_Plugins/tweaks/views/${viewName}.html`;
}
export class views {
static mediaPicker = getViewUrl("media-picker");
}
}
interface IUmbracoInterceptor<T> {
request: (config: ng.IRequestConfig) => void;
response: (response: ng.IHttpPromiseCallbackArg<T>) => void;
}
angular.module('umbraco.services').config(["$httpProvider", ($httpProvider: ng.IHttpProvider) => {
function processUrl(requestUrl: string, compareUrl: string) {
return requestUrl.indexOf(compareUrl) === 0;
}
function tweakSearchForMedia($q: ng.IQService): IUmbracoInterceptor<umb.services.IMediaPickerModel> {
return {
request: (config) => {
if (processUrl(config.url, umbraco.dialogs.mediaPicker)) {
config.url = tweak.views.mediaPicker;
}
return config || $q.when(config);
},
response: (response) => {
if (processUrl(response.config.url, tweak.views.mediaPicker)) {
}
return response;
}
};
}
$httpProvider.interceptors.push(tweakSearchForMedia);
}]);
module umbraco {
enum ViewType {
Dialogs,
Directives
}
enum UmbracoApiController {
Media
}
export function getViewUrlByTypeAndName(viewType: ViewType, viewName: string) {
switch (viewType) {
case ViewType.Dialogs:
return `views/common/dialogs/${viewName}.html`;
case ViewType.Directives:
return `views/directives/html/${viewName}.html`;
}
}
export function getApiUrlByControllerAndAction(controller: UmbracoApiController, action: string) {
switch (controller) {
case UmbracoApiController.Media:
return `/umbraco/backoffice/UmbracoApi/Media/${action}.html`;
}
}
export class api {
static media_getChildren = getApiUrlByControllerAndAction(UmbracoApiController.Media, "GetChildren");
}
export class dialogs {
static mediaPicker = getViewUrlByTypeAndName(ViewType.Dialogs, "mediaPicker");
}
export class directives {
static umb_photo_folder = getViewUrlByTypeAndName(ViewType.Directives, "mediaPicker/umb-photo-folder");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment