Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 5.96 KB | None | 0 0
  1. package foatto.core_web
  2.  
  3. import foatto.core.link.*
  4. import foatto.core_web.external.vue.that
  5. import foatto.core_web.external.vue.vueComponentOptions
  6. import kotlin.js.json
  7.  
  8. @Suppress("UnsafeCastFromDynamic")
  9. fun appControl( startAppParam: String, tabIndex: Int ) = vueComponentOptions().apply {
  10.  
  11.     this.template = """
  12.        <div>
  13.            <div v-if="responseCode == '${ResponseCode.LOGON_NEED}' || responseCode == '${ResponseCode.LOGON_FAILED}'">
  14.                <span v-if="responseCode == '${ResponseCode.LOGON_FAILED}'">"Ошибка входа в систему:", "Имя пользователя или пароль неправильны."</span>
  15.                <div>
  16.                    Вход в систему
  17.                </div>
  18.                <input v-model="login" placeholder="Имя пользователя">
  19.                <input v-model="password" placeholder="Пароль">
  20.                <button v-on:click="logon">Вход в систему</button>
  21.            </div>
  22.            <div v-else-if="responseCode == '${ResponseCode.LOGON_SYSTEM_BLOCKED}'">
  23.                "Ошибка входа в систему", "Слишком много неудачных попыток входа. \nПользователь временно заблокирован. \nПопробуйте войти попозже."
  24.            </div>
  25.            <div v-else-if="responseCode == '${ResponseCode.LOGON_ADMIN_BLOCKED}'">
  26.                "Ошибка входа в систему", "Пользователь заблокирован администратором."
  27.            </div>
  28.            <component v-else-if="responseCode == '${ResponseCode.TABLE}' || responseCode == '${ResponseCode.FORM}' ||
  29.                                   responseCode == '${ResponseCode.GRAPHIC}' || responseCode == '${ResponseCode.XY}'"
  30.                       v-bind:is="curControl">
  31.            </component>
  32.            <div v-else>
  33.                Ответ-нежданчик: {{responseCode}}
  34.            </div>
  35.        </div>
  36.    """
  37.  
  38.     this.methods = json(
  39.         "invoke" to { appRequest: AppRequest ->
  40.             //--- для проброса this внутрь лямбд
  41.             val that = that()
  42.             invokeApp( appRequest, { appResponse: AppResponse ->
  43.                 //--- из-за особенности (ошибки?) сравнения enum-значений, одно из которых берётся из десериализации json-объекта,
  44.                 //--- используем сравнение .toString() значений
  45.                 when( appResponse.code.toString() ) {
  46.                     //--- если требуется вход - сохраним последний запрос
  47.                     ResponseCode.LOGON_NEED.toString() -> {
  48.                         that.prevRequest = appRequest
  49.                         that.responseCode = appResponse.code
  50.                     }
  51.                     //--- если вход успешен - повторим последний запрос
  52.                     ResponseCode.LOGON_SUCCESS.toString(), ResponseCode.LOGON_SUCCESS_BUT_OLD.toString() -> {
  53. //                            if( appResponse.code == Code.LOGON_SUCCESS_BUT_OLD )
  54. //                                showWarning( "Система безопасности", "Срок действия пароля истек.\nПожалуйста, смените пароль." )
  55. //
  56. //                            appContainer.setUserProperties( appResponse.hmUserProperty!! )
  57.  
  58.                         that.`$parent`.setMenuBar( menuBar( appResponse.alMenuData!! ) )
  59.  
  60.                         //--- перевызовем сервер с предыдущей (до-логинной) командой
  61.                         val prevRequest = that.prevRequest.unsafeCast<AppRequest>()
  62.                         that.invoke( prevRequest )
  63.                     }
  64.                     ResponseCode.REDIRECT.toString() -> {
  65.                         that.invoke( AppRequest( appResponse.redirect!! ) )
  66.                     }
  67.                     ResponseCode.TABLE.toString() -> {
  68.                         that.curControl = tableControl( appRequest.action, appResponse.table!!, tabIndex )
  69.                         that.responseCode = appResponse.code
  70.                     }
  71.                     ResponseCode.FORM.toString() -> {
  72.                         that.curControl = formControl( appRequest.action, appResponse.form!!, tabIndex )
  73.                         that.responseCode = appResponse.code
  74.                     }
  75.                     ResponseCode.GRAPHIC.toString() -> {
  76.                         that.curControl = graphicControl( appRequest.action, appResponse.graphic!!, tabIndex )
  77.                         that.responseCode = appResponse.code
  78.                     }
  79.                     ResponseCode.XY.toString() -> {
  80.                         that.curControl = json( "template" to "<div>КАРТА</div>" )
  81.                         that.responseCode = appResponse.code
  82.                     }
  83.                     else -> {
  84.                         that.responseCode = appResponse.code
  85.                     }
  86.                 }
  87.             } )
  88. //                    }
  89.         },
  90.         "logon" to {
  91.             val login = that().login.unsafeCast<String>()
  92.             val password = that().password.unsafeCast<String>()
  93.             //val password = encodePassword( loginParams.password )
  94.             val logonRequest = LogonRequest( login, password )
  95.             //logonRequest.hmSystemProperties.putAll( getSystemProperties() )
  96.  
  97.             that().invoke( AppRequest( action = AppAction.LOGON, logon = logonRequest ) )
  98.         }
  99.     )
  100.     this.mounted = {
  101.         that().invoke( AppRequest( action = startAppParam ) )
  102.     }
  103.     this.data = {
  104.         json(
  105.             "responseCode" to "",
  106.             "login" to "",
  107.             "password" to "",
  108.             "prevRequest" to null,
  109.             "curControl" to null
  110.         )
  111.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement