Ignore:
Timestamp:
May 9, 2011, 2:56:55 PM (13 years ago)
Author:
Evgeny Stambulchik <Evgeny.Stambulchik@…>
Branch:
default
Phase:
public
Message:

Implemented optional (enabled by default) saving favorites with
configurations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/class/pf/Application.js

    r249 r251  
    21172117        },
    21182118
    2119         savePreferences : function()
    2120         {
    2121             if (this.prefs) {
    2122                 var prefstr = qx.util.Json.stringify(this.prefs);
    2123                 qx.bom.Cookie.set("pf_prefs", prefstr, 3650);
    2124             }
    2125         },
    2126        
    2127         loadPreferences : function()
    2128         {
    2129             var prefstr = qx.bom.Cookie.get("pf_prefs");
    2130            
    2131             if (prefstr) {
    2132                 this.prefs = qx.util.Json.parse(prefstr);
    2133             }
    2134            
    2135             if (!this.prefs) {
    2136                 this.prefs = new Object;
    2137             }
    2138  
    2139             if (undefined === this.prefs.rememberWindowSize) {
    2140                 this.prefs.rememberWindowSize = false;
    2141             }
    2142 
    2143             if (undefined === this.prefs.autoLoadWiki) {
    2144                 this.prefs.autoLoadWiki = true;
    2145             }
    2146            
    2147             if (undefined === this.prefs.warnOnExit) {
    2148                 this.prefs.warnOnExit = true;
    2149             }
    2150            
    2151             if (!this.prefs.units) {
    2152                 this.prefs.units = new Object;
    2153             }
    2154            
    2155             if (!this.prefs.currentConfigName) {
    2156                 this.prefs.currentConfigName = "Untitled";
    2157             }
    2158            
    2159             if (!this.prefs.configPtrs) {
    2160                 this.prefs.configPtrs = new Array;
    2161             }
    2162         },
    2163 
    2164         saveFavorites : function()
     2119        exportFavorites : function()
    21652120        {
    21662121            var sfavs = new Array;
    21672122            var len = this.favorites.length;
     2123           
    21682124            for (var k = 0; k < len; k++) {
    21692125                var fav  = this.favorites[k];
     
    21802136                    sfav.s2_id = null;
    21812137                }
    2182                 sfav.color      = fav.color;
     2138                sfav.color     = fav.color;
    21832139                sfavs.push(sfav);
    21842140            }
    21852141           
    2186             var favstr = qx.util.Json.stringify(sfavs);
    2187             qx.bom.Cookie.set("pf_favs", favstr, 3650);
    2188         },
    2189        
    2190         loadFavorites : function()
    2191         {
     2142            return sfavs;
     2143        },
     2144
     2145        importFavorites : function(sfavs)
     2146        {
     2147            if (!sfavs) {
     2148                return false;
     2149            }
     2150
    21922151            this.favorites = new Array;
    21932152           
    2194             var favstr = qx.bom.Cookie.get("pf_favs");
    2195            
    2196             if (favstr) {
    2197                 var sfavs = qx.util.Json.parse(favstr);
    2198                 if (!sfavs) {
    2199                     return;
    2200                 }
    2201                
    2202                 var len = sfavs.length;
    2203                 for (var k = 0; k < len; k++) {
    2204                     var sfav = sfavs[k];
    2205                     var fav  = new Object;
    2206                     fav.entity = this.getEntityById(sfav.entity_id);
    2207                     // old format
    2208                     if (sfav.species_id) {
    2209                         fav.s1 = this.getSpeciesById(sfav.species_id);
    2210                     } else
    2211                     if (sfav.s1_id) {
    2212                         fav.s1 = this.getSpeciesById(sfav.s1_id);
    2213                     }
    2214 
    2215                     if (sfav.s2_id) {
    2216                         fav.s2 = this.getSpeciesById(sfav.s2_id);
    2217                     }
    2218                     fav.color = sfav.color;
    2219                    
    2220                     if (fav.entity && fav.color) {
    2221                         this.favorites.push(fav);
    2222                     }
    2223                 }
    2224             }
    2225         },
    2226        
     2153            var len = sfavs.length;
     2154            for (var k = 0; k < len; k++) {
     2155                var sfav = sfavs[k];
     2156                var fav  = new Object;
     2157                fav.entity = this.getEntityById(sfav.entity_id);
     2158                // old format
     2159                if (sfav.species_id) {
     2160                    fav.s1 = this.getSpeciesById(sfav.species_id);
     2161                } else
     2162                if (sfav.s1_id) {
     2163                    fav.s1 = this.getSpeciesById(sfav.s1_id);
     2164                }
     2165
     2166                if (sfav.s2_id) {
     2167                    fav.s2 = this.getSpeciesById(sfav.s2_id);
     2168                }
     2169                fav.color = sfav.color;
     2170
     2171                if (fav.entity && fav.color) {
     2172                    this.favorites.push(fav);
     2173                }
     2174            }
     2175           
     2176            return true;
     2177        },
     2178
    22272179        getConfig : function(name)
    22282180        {
     
    22452197        },
    22462198       
     2199        savePreferences : function()
     2200        {
     2201            if (this.prefs) {
     2202                var prefstr = qx.util.Json.stringify(this.prefs);
     2203                qx.bom.Cookie.set("pf_prefs", prefstr, 3650);
     2204            }
     2205        },
     2206       
     2207        loadPreferences : function()
     2208        {
     2209            var prefstr = qx.bom.Cookie.get("pf_prefs");
     2210           
     2211            if (prefstr) {
     2212                this.prefs = qx.util.Json.parse(prefstr);
     2213            }
     2214           
     2215            if (!this.prefs) {
     2216                this.prefs = new Object;
     2217            }
     2218 
     2219            if (undefined === this.prefs.saveFavsWithConfig) {
     2220                this.prefs.saveFavsWithConfig = true;
     2221            }
     2222           
     2223            if (undefined === this.prefs.rememberWindowSize) {
     2224                this.prefs.rememberWindowSize = false;
     2225            }
     2226
     2227            if (undefined === this.prefs.autoLoadWiki) {
     2228                this.prefs.autoLoadWiki = true;
     2229            }
     2230           
     2231            if (undefined === this.prefs.warnOnExit) {
     2232                this.prefs.warnOnExit = true;
     2233            }
     2234           
     2235            if (!this.prefs.units) {
     2236                this.prefs.units = new Object;
     2237            }
     2238           
     2239            if (!this.prefs.currentConfigName) {
     2240                this.prefs.currentConfigName = "Untitled";
     2241            }
     2242           
     2243            if (!this.prefs.configPtrs) {
     2244                this.prefs.configPtrs = new Array;
     2245            }
     2246        },
     2247       
     2248        saveFavorites : function()
     2249        {
     2250            var sfavs = this.exportFavorites();
     2251           
     2252            var favstr = qx.util.Json.stringify(sfavs);
     2253           
     2254            qx.bom.Cookie.set("pf_favs", favstr, 3650);
     2255        },
     2256       
     2257        loadFavorites : function()
     2258        {
     2259            this.favorites = new Array;
     2260           
     2261            var favstr = qx.bom.Cookie.get("pf_favs");
     2262           
     2263            if (favstr) {
     2264                var sfavs = qx.util.Json.parse(favstr);
     2265               
     2266                this.importFavorites(sfavs);
     2267            }
     2268        },
     2269       
    22472270        saveConfig : function(name)
    22482271        {
     
    22902313            config.n_u = this.plasma.n_u;
    22912314            config.n_l = this.plasma.n_l;
     2315           
     2316            if (this.prefs.saveFavsWithConfig) {
     2317                config.favorites = this.exportFavorites();
     2318            }
    22922319           
    22932320            var configstr = qx.util.Json.stringify(config);
     
    23512378                this.plasma.n_u = config.n_u;
    23522379                this.plasma.n_l = config.n_l;
     2380               
     2381                if (this.prefs.saveFavsWithConfig && config.favorites) {
     2382                    this.importFavorites(config.favorites);
     2383                }
    23532384
    23542385                this.prefs.currentConfigName = name;
     
    25292560                                this.updatePlasmaParameters();
    25302561                                this.updateGUI();
     2562                                if (this.prefs.saveFavsWithConfig) {
     2563                                    this.rePopulateTree();
     2564                                }
    25312565                                this.drawAll();
    25322566                                this.saveLoadWindow.close();
     
    25572591           
    25582592            var fr, l, e;
     2593
     2594            fr = new qx.ui.groupbox.GroupBox("General");
     2595            fr.setLayout(new qx.ui.layout.VBox(10));
     2596            w.add(fr);
     2597
     2598            e = new qx.ui.form.CheckBox("Save favorites with configurations");
     2599            e.setValue(this.prefs.saveFavsWithConfig);
     2600            e.addListener("changeValue", function(ev) {
     2601                this.prefs.saveFavsWithConfig = ev.getTarget().getValue();
     2602                this.savePreferences();
     2603            }, this);
     2604            fr.add(e);
    25592605           
    25602606            fr = new qx.ui.groupbox.GroupBox("Default units");
Note: See TracChangeset for help on using the changeset viewer.