Last active
February 12, 2016 00:49
-
-
Save matijagrcic/065862ca37b8b2fcd0ff to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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); | |
}]); |
This file contains hidden or 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
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