2014-02-02 06:36:31 -07:00
( function ( $ , document , window ) {
2013-02-20 18:33:05 -07:00
2014-02-02 12:31:56 -07:00
var currentType ;
2014-02-02 06:36:31 -07:00
function loadTabs ( page , tabs ) {
var html = '' ;
for ( var i = 0 , length = tabs . length ; i < length ; i ++ ) {
var tab = tabs [ i ] ;
2014-05-12 11:04:25 -07:00
var isChecked = i == 0 ? ' selected="selected"' : '' ;
2014-02-02 12:31:56 -07:00
2014-05-12 11:04:25 -07:00
html += '<option value="' + tab . type + '"' + isChecked + '>' + tab . name + '</option>' ;
2014-02-02 06:36:31 -07:00
}
2014-05-12 11:04:25 -07:00
$ ( '#selectItemType' , page ) . html ( html ) . selectmenu ( 'refresh' ) . trigger ( 'change' ) ;
2014-02-02 06:36:31 -07:00
Dashboard . hideLoadingMsg ( ) ;
}
function loadType ( page , type ) {
2013-02-20 18:33:05 -07:00
Dashboard . showLoadingMsg ( ) ;
2014-02-02 12:31:56 -07:00
currentType = type ;
2014-02-02 06:36:31 -07:00
var promise1 = ApiClient . getServerConfiguration ( ) ;
var promise2 = $ . getJSON ( ApiClient . getUrl ( "System/Configuration/MetadataPlugins" ) ) ;
$ . when ( promise1 , promise2 ) . done ( function ( response1 , response2 ) {
2014-02-02 12:31:56 -07:00
var config = response1 [ 0 ] ;
var metadataPlugins = response2 [ 0 ] ;
config = config . MetadataOptions . filter ( function ( c ) {
return c . ItemType == type ;
} ) [ 0 ] ;
if ( config ) {
renderType ( page , type , config , metadataPlugins ) ;
Dashboard . hideLoadingMsg ( ) ;
} else {
$ . getJSON ( ApiClient . getUrl ( "System/Configuration/MetadataOptions/Default" ) ) . done ( function ( defaultConfig ) {
config = defaultConfig ;
renderType ( page , type , config , metadataPlugins ) ;
Dashboard . hideLoadingMsg ( ) ;
} ) ;
}
2013-02-20 18:33:05 -07:00
} ) ;
2013-10-15 08:29:19 -07:00
2014-02-02 06:36:31 -07:00
}
2014-02-02 12:31:56 -07:00
function setVisibilityOfBackdrops ( elem , visible ) {
if ( visible ) {
elem . show ( ) ;
$ ( 'input' , elem ) . attr ( 'required' , 'required' ) ;
} else {
elem . hide ( ) ;
$ ( 'input' , elem ) . attr ( 'required' , '' ) . removeAttr ( 'required' ) ;
}
}
2014-02-02 06:36:31 -07:00
function renderType ( page , type , config , metadataPlugins ) {
var metadataInfo = metadataPlugins . filter ( function ( f ) {
return type == f . ItemType ;
} ) [ 0 ] ;
2014-02-02 12:31:56 -07:00
setVisibilityOfBackdrops ( $ ( '.backdropFields' , page ) , metadataInfo . SupportedImageTypes . indexOf ( 'Backdrop' ) != - 1 ) ;
setVisibilityOfBackdrops ( $ ( '.screenshotFields' , page ) , metadataInfo . SupportedImageTypes . indexOf ( 'Screenshot' ) != - 1 ) ;
2014-02-02 09:59:14 -07:00
2014-02-02 06:36:31 -07:00
$ ( '.imageType' , page ) . each ( function ( ) {
var imageType = this . getAttribute ( 'data-imagetype' ) ;
if ( metadataInfo . SupportedImageTypes . indexOf ( imageType ) == - 1 ) {
$ ( this ) . hide ( ) ;
} else {
$ ( this ) . show ( ) ;
}
2014-02-02 12:31:56 -07:00
if ( getImageConfig ( config , imageType ) . Limit ) {
$ ( 'input' , this ) . checked ( true ) . checkboxradio ( 'refresh' ) ;
} else {
$ ( 'input' , this ) . checked ( false ) . checkboxradio ( 'refresh' ) ;
}
2014-02-02 06:36:31 -07:00
} ) ;
2014-02-02 12:31:56 -07:00
var backdropConfig = getImageConfig ( config , 'Backdrop' ) ;
$ ( '#txtMaxBackdrops' , page ) . val ( backdropConfig . Limit ) ;
$ ( '#txtMinBackdropDownloadWidth' , page ) . val ( backdropConfig . MinWidth ) ;
var screenshotConfig = getImageConfig ( config , 'Screenshot' ) ;
$ ( '#txtMaxScreenshots' , page ) . val ( screenshotConfig . Limit ) ;
$ ( '#txtMinScreenshotDownloadWidth' , page ) . val ( screenshotConfig . MinWidth ) ;
2014-02-02 06:36:31 -07:00
renderMetadataLocals ( page , type , config , metadataInfo ) ;
renderMetadataFetchers ( page , type , config , metadataInfo ) ;
renderMetadataSavers ( page , type , config , metadataInfo ) ;
renderImageFetchers ( page , type , config , metadataInfo ) ;
}
2014-02-02 12:31:56 -07:00
function getImageConfig ( config , type ) {
return config . ImageOptions . filter ( function ( i ) {
return i . Type == type ;
} ) [ 0 ] || {
Type : type ,
MinWidth : type == 'Backdrop' ? 1280 : 0 ,
Limit : type == 'Backdrop' ? 3 : 1
} ;
}
2014-02-02 06:36:31 -07:00
function renderImageFetchers ( page , type , config , metadataInfo ) {
var plugins = metadataInfo . Plugins . filter ( function ( p ) {
return p . Type == 'ImageFetcher' ;
} ) ;
var html = '' ;
if ( ! plugins . length ) {
$ ( '.imageFetchers' , page ) . html ( html ) . hide ( ) . trigger ( 'create' ) ;
return ;
}
2014-02-10 21:55:01 -07:00
var i , length , plugin , id ;
2014-02-02 06:36:31 -07:00
2014-02-10 21:55:01 -07:00
html += '<div class="ui-controlgroup-label" style="margin-bottom:0;padding-left:2px;">Image Fetchers:</div>' ;
2014-02-02 06:36:31 -07:00
2014-02-11 14:41:01 -07:00
html += '<div style="display:inline-block;width: 75%;vertical-align:top;">' ;
html += '<div data-role="controlgroup" class="imageFetcherGroup">' ;
2014-02-10 21:55:01 -07:00
for ( i = 0 , length = plugins . length ; i < length ; i ++ ) {
2014-02-02 06:36:31 -07:00
2014-02-10 21:55:01 -07:00
plugin = plugins [ i ] ;
2014-02-02 06:36:31 -07:00
2014-02-10 21:55:01 -07:00
id = 'chkImageFetcher' + i ;
var isChecked = config . DisabledImageFetchers . indexOf ( plugin . Name ) == - 1 ? ' checked="checked"' : '' ;
html += '<input class="chkImageFetcher" type="checkbox" name="' + id + '" id="' + id + '" data-pluginname="' + plugin . Name + '" data-mini="true"' + isChecked + '>' ;
2014-02-02 06:36:31 -07:00
html += '<label for="' + id + '">' + plugin . Name + '</label>' ;
}
2014-02-10 21:55:01 -07:00
html += '</div>' ;
html += '</div>' ;
if ( plugins . length > 1 ) {
html += '<div style="display:inline-block;vertical-align:top;margin-left:5px;">' ;
for ( i = 0 , length = plugins . length ; i < length ; i ++ ) {
2014-02-11 14:41:01 -07:00
html += '<div style="margin:6px 0;">' ;
2014-02-10 21:55:01 -07:00
if ( i == 0 ) {
2014-02-11 14:41:01 -07:00
html += '<button data-inline="true" disabled="disabled" class="btnUp" data-pluginindex="' + i + '" type="button" data-icon="arrow-u" data-mini="true" data-iconpos="notext" style="margin: 0 1px;">Up</button>' ;
html += '<button data-inline="true" class="btnDown" data-pluginindex="' + i + '" type="button" data-icon="arrow-d" data-mini="true" data-iconpos="notext" style="margin: 0 1px;">Down</button>' ;
} else if ( i == ( plugins . length - 1 ) ) {
html += '<button data-inline="true" class="btnUp" data-pluginindex="' + i + '" type="button" data-icon="arrow-u" data-mini="true" data-iconpos="notext" style="margin: 0 1px;">Up</button>' ;
html += '<button data-inline="true" disabled="disabled" class="btnDown" data-pluginindex="' + i + '" type="button" data-icon="arrow-d" data-mini="true" data-iconpos="notext" style="margin: 0 1px;">Down</button>' ;
}
else {
html += '<button data-inline="true" class="btnUp" data-pluginindex="' + i + '" type="button" data-icon="arrow-u" data-mini="true" data-iconpos="notext" style="margin: 0 1px;">Up</button>' ;
html += '<button data-inline="true" class="btnDown" data-pluginindex="' + i + '" type="button" data-icon="arrow-d" data-mini="true" data-iconpos="notext" style="margin: 0 1px;">Down</button>' ;
2014-02-10 21:55:01 -07:00
}
2014-02-11 14:41:01 -07:00
html += '</div>' ;
2014-02-10 21:55:01 -07:00
}
}
html += '</div>' ;
2014-02-11 14:41:01 -07:00
html += '<div class="fieldDescription" style="width:75%;">Enable and rank your preferred image fetchers in order of priority.</div>' ;
var elem = $ ( '.imageFetchers' , page ) . html ( html ) . show ( ) . trigger ( 'create' ) ;
$ ( '.btnDown' , elem ) . on ( 'click' , function ( ) {
var index = parseInt ( this . getAttribute ( 'data-pluginindex' ) ) ;
2014-02-02 06:36:31 -07:00
2014-02-11 14:41:01 -07:00
var elemToMove = $ ( '.imageFetcherGroup .ui-checkbox' , page ) [ index ] ;
var insertAfter = $ ( elemToMove ) . next ( '.ui-checkbox' ) [ 0 ] ;
elemToMove . parentNode . removeChild ( elemToMove ) ;
$ ( elemToMove ) . insertAfter ( insertAfter ) ;
$ ( '.imageFetcherGroup' , page ) . controlgroup ( 'destroy' ) . controlgroup ( ) ;
} ) ;
$ ( '.btnUp' , elem ) . on ( 'click' , function ( ) {
var index = parseInt ( this . getAttribute ( 'data-pluginindex' ) ) ;
var elemToMove = $ ( '.imageFetcherGroup .ui-checkbox' , page ) [ index ] ;
var insertBefore = $ ( elemToMove ) . prev ( '.ui-checkbox' ) [ 0 ] ;
elemToMove . parentNode . removeChild ( elemToMove ) ;
$ ( elemToMove ) . insertBefore ( insertBefore ) ;
$ ( '.imageFetcherGroup' , page ) . controlgroup ( 'destroy' ) . controlgroup ( ) ;
} ) ;
2014-02-02 06:36:31 -07:00
}
function renderMetadataSavers ( page , type , config , metadataInfo ) {
var plugins = metadataInfo . Plugins . filter ( function ( p ) {
return p . Type == 'MetadataSaver' ;
} ) ;
var html = '' ;
if ( ! plugins . length ) {
$ ( '.metadataSavers' , page ) . html ( html ) . hide ( ) . trigger ( 'create' ) ;
return ;
}
html += '<fieldset data-role="controlgroup">' ;
html += '<legend>Metadata Savers:</legend>' ;
for ( var i = 0 , length = plugins . length ; i < length ; i ++ ) {
var plugin = plugins [ i ] ;
var id = 'chkMetadataSaver' + i ;
2014-02-02 12:31:56 -07:00
var isChecked = config . DisabledMetadataSavers . indexOf ( plugin . Name ) == - 1 ? ' checked="checked"' : '' ;
html += '<input class="chkMetadataSaver" type="checkbox" name="' + id + '" id="' + id + '" data-mini="true"' + isChecked + ' data-pluginname="' + plugin . Name + '">' ;
2014-02-02 06:36:31 -07:00
html += '<label for="' + id + '">' + plugin . Name + '</label>' ;
}
html += '</fieldset>' ;
2014-02-10 11:39:41 -07:00
html += '<div class="fieldDescription">Choose the file formats to save your metadata to.</div>' ;
2014-02-02 06:36:31 -07:00
$ ( '.metadataSavers' , page ) . html ( html ) . show ( ) . trigger ( 'create' ) ;
}
function renderMetadataFetchers ( page , type , config , metadataInfo ) {
var plugins = metadataInfo . Plugins . filter ( function ( p ) {
return p . Type == 'MetadataFetcher' ;
} ) ;
var html = '' ;
if ( ! plugins . length ) {
$ ( '.metadataFetchers' , page ) . html ( html ) . hide ( ) . trigger ( 'create' ) ;
return ;
}
2014-02-10 21:55:01 -07:00
var i , length , plugin , id ;
2014-02-02 06:36:31 -07:00
2014-02-19 21:53:15 -07:00
html += '<div class="ui-controlgroup-label" style="margin-bottom:0;padding-left:2px;">Metadata Downloaders:</div>' ;
2014-02-02 06:36:31 -07:00
2014-02-11 14:41:01 -07:00
html += '<div style="display:inline-block;width: 75%;vertical-align:top;">' ;
html += '<div data-role="controlgroup" class="metadataFetcherGroup">' ;
2014-02-10 21:55:01 -07:00
for ( i = 0 , length = plugins . length ; i < length ; i ++ ) {
2014-02-02 06:36:31 -07:00
2014-02-10 21:55:01 -07:00
plugin = plugins [ i ] ;
2014-02-02 06:36:31 -07:00
2014-02-10 21:55:01 -07:00
id = 'chkMetadataFetcher' + i ;
var isChecked = config . DisabledMetadataFetchers . indexOf ( plugin . Name ) == - 1 ? ' checked="checked"' : '' ;
html += '<input class="chkMetadataFetcher" type="checkbox" name="' + id + '" id="' + id + '" data-pluginname="' + plugin . Name + '" data-mini="true"' + isChecked + '>' ;
2014-02-02 06:36:31 -07:00
html += '<label for="' + id + '">' + plugin . Name + '</label>' ;
}
2014-02-10 21:55:01 -07:00
html += '</div>' ;
html += '</div>' ;
if ( plugins . length > 1 ) {
html += '<div style="display:inline-block;vertical-align:top;margin-left:5px;">' ;
for ( i = 0 , length = plugins . length ; i < length ; i ++ ) {
2014-02-11 14:41:01 -07:00
html += '<div style="margin:6px 0;">' ;
2014-02-10 21:55:01 -07:00
if ( i == 0 ) {
2014-02-11 14:41:01 -07:00
html += '<button data-inline="true" disabled="disabled" class="btnUp" data-pluginindex="' + i + '" type="button" data-icon="arrow-u" data-mini="true" data-iconpos="notext" style="margin: 0 1px;">Up</button>' ;
html += '<button data-inline="true" class="btnDown" data-pluginindex="' + i + '" type="button" data-icon="arrow-d" data-mini="true" data-iconpos="notext" style="margin: 0 1px;">Down</button>' ;
} else if ( i == ( plugins . length - 1 ) ) {
html += '<button data-inline="true" class="btnUp" data-pluginindex="' + i + '" type="button" data-icon="arrow-u" data-mini="true" data-iconpos="notext" style="margin: 0 1px;">Up</button>' ;
html += '<button data-inline="true" disabled="disabled" class="btnDown" data-pluginindex="' + i + '" type="button" data-icon="arrow-d" data-mini="true" data-iconpos="notext" style="margin: 0 1px;">Down</button>' ;
}
else {
html += '<button data-inline="true" class="btnUp" data-pluginindex="' + i + '" type="button" data-icon="arrow-u" data-mini="true" data-iconpos="notext" style="margin: 0 1px;">Up</button>' ;
html += '<button data-inline="true" class="btnDown" data-pluginindex="' + i + '" type="button" data-icon="arrow-d" data-mini="true" data-iconpos="notext" style="margin: 0 1px;">Down</button>' ;
2014-02-10 21:55:01 -07:00
}
2014-02-11 14:41:01 -07:00
html += '</div>' ;
2014-02-10 21:55:01 -07:00
}
}
html += '</div>' ;
2014-02-19 21:53:15 -07:00
html += '<div class="fieldDescription" style="width:75%;">Enable and rank your preferred metadata downloaders in order of priority. Lower priority downloaders will only be used to fill in missing information.</div>' ;
2014-02-11 14:41:01 -07:00
var elem = $ ( '.metadataFetchers' , page ) . html ( html ) . show ( ) . trigger ( 'create' ) ;
$ ( '.btnDown' , elem ) . on ( 'click' , function ( ) {
var index = parseInt ( this . getAttribute ( 'data-pluginindex' ) ) ;
2014-02-02 06:36:31 -07:00
2014-02-11 14:41:01 -07:00
var elemToMove = $ ( '.metadataFetcherGroup .ui-checkbox' , page ) [ index ] ;
var insertAfter = $ ( elemToMove ) . next ( '.ui-checkbox' ) [ 0 ] ;
elemToMove . parentNode . removeChild ( elemToMove ) ;
$ ( elemToMove ) . insertAfter ( insertAfter ) ;
$ ( '.metadataFetcherGroup' , page ) . controlgroup ( 'destroy' ) . controlgroup ( ) ;
} ) ;
$ ( '.btnUp' , elem ) . on ( 'click' , function ( ) {
var index = parseInt ( this . getAttribute ( 'data-pluginindex' ) ) ;
var elemToMove = $ ( '.metadataFetcherGroup .ui-checkbox' , page ) [ index ] ;
var insertBefore = $ ( elemToMove ) . prev ( '.ui-checkbox' ) [ 0 ] ;
elemToMove . parentNode . removeChild ( elemToMove ) ;
$ ( elemToMove ) . insertBefore ( insertBefore ) ;
$ ( '.metadataFetcherGroup' , page ) . controlgroup ( 'destroy' ) . controlgroup ( ) ;
} ) ;
2014-02-02 06:36:31 -07:00
}
function renderMetadataLocals ( page , type , config , metadataInfo ) {
var plugins = metadataInfo . Plugins . filter ( function ( p ) {
return p . Type == 'LocalMetadataProvider' ;
} ) ;
var html = '' ;
2014-02-10 21:55:01 -07:00
if ( plugins . length < 2 ) {
2014-02-02 06:36:31 -07:00
$ ( '.metadataReaders' , page ) . html ( html ) . hide ( ) . trigger ( 'create' ) ;
return ;
}
2014-02-10 11:39:41 -07:00
html += '<div class="ui-controlgroup-label" style="margin-bottom:0;padding-left:2px;">Preferred Local Metadata:</div>' ;
html += '<ul data-role="listview" data-inset="true" data-mini="true" style="margin-top:.5em;margin-bottom:.5em;">' ;
2014-02-02 06:36:31 -07:00
for ( var i = 0 , length = plugins . length ; i < length ; i ++ ) {
var plugin = plugins [ i ] ;
2014-02-10 11:39:41 -07:00
if ( i > 0 ) {
html += '<li data-mini="true" class="localReaderOption" data-pluginname="' + plugin . Name + '">' ;
2014-02-02 06:36:31 -07:00
2014-02-10 11:39:41 -07:00
html += '<a href="#" style="font-size:13px;font-weight:normal;">' + plugin . Name + '</a>' ;
2014-02-22 15:41:29 -07:00
html += '<a class="btnLocalReaderUp btnLocalReaderMove" data-pluginindex="' + i + '" href="#" style="font-size:13px;font-weight:normal;" data-icon="arrow-u">Up</a>' ;
2014-02-10 11:39:41 -07:00
html += '</li>' ;
}
else if ( plugins . length > 1 ) {
html += '<li data-mini="true" class="localReaderOption" data-pluginname="' + plugin . Name + '">' ;
html += '<a href="#" style="font-size:13px;font-weight:normal;">' + plugin . Name + '</a>' ;
2014-02-22 15:41:29 -07:00
html += '<a class="btnLocalReaderDown btnLocalReaderMove" data-pluginindex="' + i + '" href="#" style="font-size:13px;font-weight:normal;" data-icon="arrow-d">Down</a>' ;
2014-02-10 11:39:41 -07:00
html += '</li>' ;
}
else {
html += '<li data-mini="true" class="localReaderOption" data-pluginname="' + plugin . Name + '">' ;
html += plugin . Name ;
html += '</li>' ;
}
2014-02-02 06:36:31 -07:00
}
2014-02-10 11:39:41 -07:00
html += '</ul>' ;
html += '<div class="fieldDescription">Rank your preferred local metadata sources in order of priority. The first file found will be read.</div>' ;
2014-02-02 06:36:31 -07:00
2014-02-23 20:27:13 -07:00
$ ( '.metadataReaders' , page ) . html ( html ) . show ( ) . trigger ( 'create' ) ;
2014-02-02 06:36:31 -07:00
}
function loadPage ( page ) {
2014-05-12 11:04:25 -07:00
loadTabs ( page , [
{ name : 'Movies' , type : 'Movie' } ,
{ name : 'Trailers' , type : 'Trailer' } ,
{ name : 'Collections' , type : 'BoxSet' } ,
{ name : 'TV Series' , type : 'Series' } ,
{ name : 'TV Seasons' , type : 'Season' } ,
{ name : 'TV Episodes' , type : 'Episode' } ,
{ name : 'Games' , type : 'Game' } ,
{ name : 'Game Systems' , type : 'GameSystem' } ,
{ name : 'Game Genres' , type : 'GameGenre' } ,
{ name : 'Music Artists' , type : 'MusicArtist' } ,
{ name : 'Music Albums' , type : 'MusicAlbum' } ,
{ name : 'Music Videos' , type : 'MusicVideo' } ,
{ name : 'Music Genres' , type : 'MusicGenre' } ,
{ name : 'Songs' , type : 'Audio' } ,
{ name : 'Home Videos' , type : 'Video' } ,
{ name : 'Books' , type : 'Book' } ,
{ name : 'Adult Videos' , type : 'AdultVideo' } ,
{ name : 'People' , type : 'Person' } ,
{ name : 'Genres' , type : 'Genre' } ,
{ name : 'Studios' , type : 'Studio' }
] ) ;
2014-02-02 06:36:31 -07:00
}
2014-02-02 12:31:56 -07:00
function saveSettingsIntoConfig ( form , config ) {
config . DisabledMetadataSavers = $ ( '.chkMetadataSaver:not(:checked)' , form ) . get ( ) . map ( function ( c ) {
return c . getAttribute ( 'data-pluginname' ) ;
} ) ;
2014-02-10 21:55:01 -07:00
config . LocalMetadataReaderOrder = $ ( '.localReaderOption' , form ) . get ( ) . map ( function ( c ) {
return c . getAttribute ( 'data-pluginname' ) ;
} ) ;
config . DisabledMetadataFetchers = $ ( '.chkMetadataFetcher:not(:checked)' , form ) . get ( ) . map ( function ( c ) {
return c . getAttribute ( 'data-pluginname' ) ;
} ) ;
config . MetadataFetcherOrder = $ ( '.chkMetadataFetcher' , form ) . get ( ) . map ( function ( c ) {
return c . getAttribute ( 'data-pluginname' ) ;
} ) ;
config . DisabledImageFetchers = $ ( '.chkImageFetcher:not(:checked)' , form ) . get ( ) . map ( function ( c ) {
return c . getAttribute ( 'data-pluginname' ) ;
} ) ;
config . ImageFetcherOrder = $ ( '.chkImageFetcher' , form ) . get ( ) . map ( function ( c ) {
2014-02-10 11:39:41 -07:00
return c . getAttribute ( 'data-pluginname' ) ;
} ) ;
2014-02-02 12:31:56 -07:00
config . ImageOptions = $ ( '.imageType:visible input' , form ) . get ( ) . map ( function ( c ) {
return {
Type : $ ( c ) . parents ( '.imageType' ) . attr ( 'data-imagetype' ) ,
Limit : c . checked ? 1 : 0 ,
MinWidth : 0
} ;
} ) ;
2014-02-17 14:35:08 -07:00
config . ImageOptions . push ( {
Type : 'Backdrop' ,
Limit : $ ( '#txtMaxBackdrops' , form ) . val ( ) ,
MinWidth : $ ( '#txtMinBackdropDownloadWidth' , form ) . val ( )
} ) ;
2014-02-02 12:31:56 -07:00
2014-02-17 14:35:08 -07:00
config . ImageOptions . push ( {
Type : 'Screenshot' ,
Limit : $ ( '#txtMaxScreenshots' , form ) . val ( ) ,
MinWidth : $ ( '#txtMinScreenshotDownloadWidth' , form ) . val ( )
} ) ;
2014-02-02 12:31:56 -07:00
}
2014-02-02 06:36:31 -07:00
function onSubmit ( ) {
2013-02-20 18:33:05 -07:00
var form = this ;
2013-04-16 21:58:32 -07:00
Dashboard . showLoadingMsg ( ) ;
2013-02-20 18:33:05 -07:00
ApiClient . getServerConfiguration ( ) . done ( function ( config ) {
2014-02-02 12:31:56 -07:00
var type = currentType ;
var metadataOptions = config . MetadataOptions . filter ( function ( c ) {
return c . ItemType == type ;
} ) [ 0 ] ;
if ( metadataOptions ) {
saveSettingsIntoConfig ( form , metadataOptions ) ;
ApiClient . updateServerConfiguration ( config ) . done ( Dashboard . processServerConfigurationUpdateResult ) ;
} else {
$ . getJSON ( ApiClient . getUrl ( "System/Configuration/MetadataOptions/Default" ) ) . done ( function ( defaultOptions ) {
defaultOptions . ItemType = type ;
config . MetadataOptions . push ( defaultOptions ) ;
saveSettingsIntoConfig ( form , defaultOptions ) ;
ApiClient . updateServerConfiguration ( config ) . done ( Dashboard . processServerConfigurationUpdateResult ) ;
} ) ;
}
2013-02-20 18:33:05 -07:00
} ) ;
// Disable default form submission
return false ;
}
2014-02-23 20:27:13 -07:00
$ ( document ) . on ( 'pageinit' , "#metadataImagesConfigurationPage" , function ( ) {
var page = this ;
$ ( '.metadataReaders' , page ) . on ( 'click' , '.btnLocalReaderMove' , function ( ) {
var li = $ ( this ) . parents ( '.localReaderOption' ) ;
var ul = li . parents ( 'ul' ) ;
if ( $ ( this ) . hasClass ( 'btnLocalReaderDown' ) ) {
var next = li . next ( ) ;
li . remove ( ) . insertAfter ( next ) ;
} else {
var prev = li . prev ( ) ;
li . remove ( ) . insertBefore ( prev ) ;
}
$ ( '.localReaderOption' , ul ) . each ( function ( ) {
if ( $ ( this ) . prev ( '.localReaderOption' ) . length ) {
$ ( '.btnLocalReaderMove' , this ) . addClass ( 'btnLocalReaderUp' ) . removeClass ( 'btnLocalReaderDown' ) . attr ( 'data-icon' , 'arrow-u' ) . removeClass ( 'ui-icon-arrow-d' ) . addClass ( 'ui-icon-arrow-u' ) ;
} else {
$ ( '.btnLocalReaderMove' , this ) . addClass ( 'btnLocalReaderDown' ) . removeClass ( 'btnLocalReaderUp' ) . attr ( 'data-icon' , 'arrow-d' ) . removeClass ( 'ui-icon-arrow-u' ) . addClass ( 'ui-icon-arrow-d' ) ;
}
} ) ;
ul . listview ( 'destroy' ) . listview ( { } ) ;
} ) ;
2014-05-12 11:04:25 -07:00
$ ( '#selectItemType' , page ) . on ( 'change' , function ( ) {
loadType ( page , this . value ) ;
} ) ;
2014-02-23 20:27:13 -07:00
} ) . on ( 'pageshow' , "#metadataImagesConfigurationPage" , function ( ) {
2014-02-02 06:36:31 -07:00
Dashboard . showLoadingMsg ( ) ;
var page = this ;
loadPage ( page ) ;
} ) ;
window . MetadataImagesPage = {
onSubmit : onSubmit
} ;
} ) ( jQuery , document , window ) ;