{"size": 1693, "ext": "js", "max_stars_repo_path": "app/js/stores/rpc/captcha.js", "max_stars_repo_name": "RedOrion/Lacuna-Web-Client", "max_stars_repo_stars_event_min_datetime": "2015-02-27T17:09:20.000Z", "max_stars_repo_stars_event_max_datetime": "2017-07-29T13:49:54.000Z", "max_issues_repo_path": "app/js/stores/rpc/captcha.js", "max_issues_repo_name": "RedOrion/Lacuna-Web-Client", "max_issues_repo_issues_event_min_datetime": "2015-04-12T06:44:54.000Z", "max_issues_repo_issues_event_max_datetime": "2016-03-16T00:33:30.000Z", "max_forks_repo_path": "app/js/stores/rpc/captcha.js", "max_forks_repo_name": "RedOrion/Lacuna-Web-Client", "max_forks_repo_forks_event_min_datetime": "2015-01-14T18:50:27.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-17T13:56:24.000Z"}
{"max_stars_count": 8, "max_issues_count": 123, "max_forks_count": 20, "avg_line_length": 24.8970588235, "max_line_length": 70, "alphanum_fraction": 0.5829887773}
'use strict';

var Reflux                  = require('reflux');
var StatefulMixinStore      = require('js/stores/mixins/stateful');

var CaptchaWindowActions    = require('js/actions/windows/captcha');
var CaptchaRPCActions       = require('js/actions/rpc/captcha');
var WindowManagerActions    = require('js/actions/windowManager');
var WindowsActions          = require('js/actions/window');

var CaptchaWindow           = require('js/components/window/captcha');

var server                  = require('js/server');
var clone                   = require('js/util').clone;

var CaptchaRPCStore = Reflux.createStore({
    listenables : [
        CaptchaWindowActions,
        CaptchaRPCActions
    ],

    mixins : [
        StatefulMixinStore
    ],

    getDefaultData : function() {
        return {
            guid    : '',
            url     : '',
            solved  : 0,
            window  : ''
        };
    },

    onCaptchaWindowClear : function() {
        this.emit(this.getDefaultData());
    },


    onSuccessCaptchaRPCFetch : function(result) {
        var update = clone(this.state);
        update.guid = result.guid;
        update.url  = result.url;

        this.emit(update);
    },

    onSuccessCaptchaRPCSolve : function(result) {
        var update = clone(this.state);
        update.solved = 1;

        this.emit(update);
        WindowsActions.windowCloseByType('captcha');
    },

    onCaptchaWindowShow : function(window) {
        var update = clone(this.state);
        update.window = window;
        this.emit(update);
    },

    onCaptchaWindowRefresh : function() {
        this.onCaptchaWindowClear();
    }
});

module.exports = CaptchaRPCStore;
