# -*- coding: utf-8 -*-
"""
    demeter web page
    name:package.py 版本相关
    author:rabin
"""
from .__load__ import *

class version_path(Load):
	@Web.auth
	@Web.setting
	def get(self):
		self.set(
			name = u'版本'
			,path = '/package/version'
			,width = '600'
			,height = '600'
			,search = (('package_id-select-','name-input-mlike','version-input-mlike'), (u'选择Package', u'版本名称', u'版本号'))
			,thead = (u'所属Package', u'版本名称', u'版本号', u'创建时间')
			,tbody = ('package','name', 'version', 'cdate')
			,state = False
		)
		self.data['common']['search_package-select-'] = self.service('common').list('package')
		self.list('package_version')
		if self.data['list']:
			for key, value in enumerate(self.data['list']):
				package = self.service('common').one('package', id=value['package_id'])
				self.data['list'][key]['package'] = package['name']
		self.show('list')

class version_update_path(Load):
	@Web.auth
	@Web.setting
	def get(self):
		self.set(
			path = '/package/version'
			,label = (u'所属Package',u'版本名称',u'版本号')
			,update = ('package_id-select','name-input-required','name-input-required')
			,update_package_id = self.service('common').list('package')
		)
		self.one('package_version')
		self.show('update')
	@Web.auth
	@Web.setting
	def post(self):
		self.update('package_version')
	@Web.auth
	@Web.setting
	def delete(self):
		self.drop('package_version')

class package_path(Load):
	@Web.auth
	@Web.setting
	def get(self):
		self.set(
			name = u'Package'
			,path = '/package/package'
			,width = '600'
			,height = '300'
			,search = (('name-input-mlike','url-input-mlike'), (u'名称',u'地址'))
			,thead = (u'ID', u'名称',u'地址', u'更新时间')
			,tbody = ('id', 'name', 'url', 'cdate')
			,state = False
		)
		self.list('package')
		self.show('list')

class package_update_path(Load):
	@Web.auth
	@Web.setting
	def get(self):
		self.set(
			path = '/package/package'
			,label = (u'名称', u'地址')
			,update = ('name-input-required', 'url-input-required')
		)
		self.one('package')
		self.show('update')
	@Web.auth
	@Web.setting
	def post(self):
		self.update('package')
	@Web.auth
	@Web.setting
	def delete(self):
		self.drop('package')
